我想要控制打开的键盘并能够同时滚动表格 View 。我现在必须关闭键盘才能滚动表格 View 。
最佳答案
您在 viewDidLoad 中注册通知并在 viewWillDisappear 中取消注册通知
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
简单地通过键盘的高度调整tableview的contentInset,然后将单元格滚动到底部:
- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.myTableView.contentInset = contentInsets;
self.myTableView.scrollIndicatorInsets = contentInsets;
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
[UIView animateWithDuration:.3 animations:^(void)
{
self.myTableView.contentInset = UIEdgeInsetsZero;
self.myTableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}];
}
关于objective-c - 如何在键盘打开的同时滚动表格 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39261750/