self.title = @"DAKeyboardControl";
self.view.backgroundColor = [UIColor lightGrayColor];
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
self.view.bounds.size.width,
self.view.bounds.size.height - 40.0f)];
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:tableView];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f,
self.view.bounds.size.height - 40.0f,
self.view.bounds.size.width,
40.0f)];
toolBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:toolBar];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10.0f,
6.0f,
toolBar.bounds.size.width - 20.0f - 68.0f,
30.0f)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[toolBar addSubview:textField];
UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
sendButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[sendButton setTitle:@"Send" forState:UIControlStateNormal];
sendButton.frame = CGRectMake(toolBar.bounds.size.width - 68.0f,
6.0f,
58.0f,
29.0f);
[toolBar addSubview:sendButton];
self.view.keyboardTriggerOffset = toolBar.bounds.size.height;
[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView)
{
/*
Try not to call "self" inside this block (retain cycle).
But if you do, make sure to remove DAKeyboardControl
when you are done with the view controller by calling:
[self.view removeKeyboardControl];
*/
CGRect toolBarFrame = toolBar.frame;
toolBarFrame.origin.y = keyboardFrameInView.origin.y - toolBarFrame.size.height;
toolBar.frame = toolBarFrame;
CGRect tableViewFrame = tableView.frame;
tableViewFrame.size.height = toolBarFrame.origin.y;
tableView.frame = tableViewFrame;
}];