我正在使用 UIKeyboardWillShowNotification
来了解何时显示键盘并调整我的 UIWebView
的大小,以便它不会隐藏在键盘后面。
奇怪的是,当我在 NSNotificationCenter
调用的方法中更改框架时,它会以一种允许我滚动 UIWebView
内容的方式更改框架(屏幕截图中的红色),而且 UIWebView
的很大一部分滚动到 View 中(屏幕截图中的黄色)。永远不应显示黄色。
- (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];
}
}
如果我使用不同于从 NSNotificationCenter
调用的方法更改 UIWebView
框架,框架会正确更改并且键盘上方的区域仅填充我的 HTML UIWebView
(红色)中的内容。
可能导致此问题的原因是什么?
最佳答案
使用返回键盘最终预期帧的 UIKeyboardFrameEndUserInfoKey 键
关于ios - UIKeyboardWillShowNotification 错误地更改了 UIWebView 的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20964476/