解决方法
为了解决你的问题,有很多解决方案.从使用UIScrolView到更改框架或约束.
如果您想使用UIScrolView,您应该将UIView注册表格插入到UIScrolView并设置内容大小.
- (void)registerForKeyboardNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; }
之后使用方法(keyboardWasShown和keyboardWillBeHidden)的通知来改变contentInsets.
更改contentInsets的示例:
- (void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0,0.0,kbSize.height,0.0); scrollView.contentInset = contentInsets; scrollView.scrollIndicatorInsets = contentInsets; } - (void)keyboardWillBeHidden:(NSNotification*)aNotification { UIEdgeInsets contentInsets = UIEdgeInsetsZero; scrollView.contentInset = contentInsets; scrollView.scrollIndicatorInsets = contentInsets; }
最后解决方案取决于您的选择,您可以像UIScrolView参数一样更改框架或约束.