UITableView键盘遮挡 自动上移

要实现这个功能 大家都知道监听键盘的响应事件是最好的

步骤1

监听键盘的响应和失去响应的两个事件

代码如下:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

步骤2

实现监听的两个方法

代码如下:

– (void)keyboardWillShow:(NSNotification *)info{CGRect keyboardBounds = [[[info userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];_tableView.contentInset = UIEdgeInsetsMake(_tableView.contentInset.top, 0, keyboardBounds.size.height, 0);}- (void)keyboardWillHide:(NSNotification *)info{_tableView.contentInset = UIEdgeInsetsMake(_tableView.contentInset.top, 0, 0, 0);}

去试一下吧 很好用的一个小功能

,一定要记得挺身而出,即便帮不了忙,安慰也是最大的支持.

UITableView键盘遮挡 自动上移

相关文章:

你感兴趣的文章:

标签云: