显示/隐藏键盘时使用以下内容:
- (void)keyboardWasShown:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.scrDetails.contentInset = contentInsets;
self.scrDetails.scrollIndicatorInsets = contentInsets;
}
- (void)keyboardWillHide:(NSNotification *)notification
{
/* Set to NO so after the keyboard is hidden, the size goes back to normal */
self.automaticallyAdjustsScrollViewInsets = NO;
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.scrDetails.contentInset = contentInsets;
self.scrDetails.scrollIndicatorInsets = contentInsets;
[self.view layoutIfNeeded];
}
但由于某些原因,即使在解除键盘时正确设置了尺寸
(lldb) po self.scrDetails.contentInset
(top = 0, left = 0, bottom = 0, right = 0)
效果未在设备/模拟器上显示(滚动条保持在上一个键盘向上位置)
见图片
我使用autolayout,所以我没有直接设置contentSize。
有什么建议可能有助于追踪这一点吗?
答案 0 :(得分:0)
您可以使用第三方类TPKeyboardAvoiding。它管理键盘。