您的位置:首页 > 移动开发 > IOS开发

IOS TextFile键盘不遮挡 + 下拉隐藏键盘

2014-03-24 16:37 766 查看
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;
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: