ios - UIKeyboardWillShowNotification 错误地更改了 UIWebView 的框架

标签 ios objective-c uiwebview nsnotificationcenter uikeyboard

我正在使用 UIKeyboardWillShowNotification 来了解何时显示键盘并调整我的 UIWebView 的大小,以便它不会隐藏在键盘后面。

奇怪的是,当我在 NSNotificationCenter 调用的方法中更改框架时,它会以一种允许我滚动 UIWebView 内容的方式更改框架(屏幕截图中的红色),而且 UIWebView 的很大一部分滚动到 View 中(屏幕截图中的黄色)。永远不应显示黄色。

enter image description here

- (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(红色)中的内容。

enter image description here

可能导致此问题的原因是什么?

最佳答案

使用返回键盘最终预期帧的 UIKeyboardFrameEndUserInfoKey 键

关于ios - UIKeyboardWillShowNotification 错误地更改了 UIWebView 的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20964476/

相关文章:

cocoa-touch - iOS header 中的 WebKit 错误域和代码?

ios - 在页脚按钮上单击表格 View 不会重新加载表格的内容?

ios - 设置自动布局约束后, subview 没有宽度或高度

ios - Ipad 中的 Infinea Tab 集成

iphone - iOS项目目录组织

ios - UIWebView HTML字体大小问题

ios - 如果 Collection View 嵌入在 ios 中的 TableView 中,如何始终显示 Collection View 的第一项

ios - 展开/折叠 UITableView 中的单元格数组

ios - 在 ios 7 xcode 中单击 ScrollView 上方的按钮时如何滚动 ScrollView ?

ios - 在我的 iOS 应用程序中登录 Instagram 后,如何以其他用户身份登录?