我正在使用UIKeyboardWillShowNotification
来了解键盘何时显示并调整UIWebView
的大小,以便它不会隐藏在键盘后面。
奇怪的是,当我更改NSNotificationCenter
调用的方法中的帧时,它会以允许我滚动UIWebView
内容(屏幕截图中为红色)的方式更改帧,但是还有很大一部分UIWebView
滚动到视图中(屏幕截图中为黄色)。黄色永远不应该出现。
- (void)keyboardWillShowOrHide:(NSNotification *)notification {
// User Info
NSDictionary *info = notification.userInfo;
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
int curve = [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
CGRect keyboard = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
if ([notification.name isEqualToString:UIKeyboardWillShowNotification]) {
[UIView animateWithDuration:duration delay:0 options:curve animations:^{
CGRect frame = self.toolbarHolder.frame;
frame.origin.y = (self.view.frame.size.height - keyboard.size.height) - 44;
self.toolbarHolder.frame = frame;
// Editor View
CGRect editorFrame = self.editorView.frame;
editorFrame.size.height = (self.view.frame.size.height - keyboard.size.height) - 44;
self.editorView.frame = editorFrame;
} completion:nil];
} else {
[UIView animateWithDuration:duration delay:0 options:curve animations:^{
CGRect frame = self.toolbarHolder.frame;
frame.origin.y = self.view.frame.size.height;
self.toolbarHolder.frame = frame;
// Editor View
CGRect editorFrame = self.editorView.frame;
editorFrame.size.height = self.view.frame.size.height;
self.editorView.frame = editorFrame;
} completion:nil];
}
}
如果我使用与UIWebView
调用的方法不同的方法更改NSNotificationCenter
框架,则框架会正确更改,键盘上方的区域仅填充{{1 (红色)。
可能导致此问题的原因是什么?
答案 0 :(得分:2)
使用UIKeyboardFrameEndUserInfoKey键返回键盘的最终预期帧