【问题标题】:Adjusting view frame for iOS hardware keyboard调整 iOS 硬件键盘的视图框架
【发布时间】:2015-03-13 04:11:33
【问题描述】:

我按照此处的说明使用 iOS 键盘调整视图。 https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

这不适用于硬件键盘。当文本视图处于活动状态时,不会显示 iOS 键盘,但示例代码仍会返回键盘的完整高度。在我的例子中,屏幕上只显示了输入附件视图。

如何检测这种情况并仅针对输入附件视图调整我的视图?

【问题讨论】:

标签: ios objective-c keyboard


【解决方案1】:

您可以在我的回答https://stackoverflow.com/a/36553555/1049134 中将键盘的框架与当前窗口相交。

【讨论】:

    【解决方案2】:

    遇到了同样的问题。 看起来 iOS 键盘已完全实例化,并且在连接硬件键盘时只是移出视图部分。因此键盘的大小是合适的。只是没有完全显示出来。

    在检查了通知之后,我自己计算了可见的键盘高度来解决它。 在我的示例中,我正在收听 UIKeyboardWillShowNotification、UIKeyboardWillChangeFrameNotification 和 UIKeyboardWillHideNotification。

    -(void)keyboardMessage:(NSNotification*)notification {
            NSDictionary *userInfo = notification.userInfo;
            CGFloat duration = [userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
            NSValue *value = userInfo[@"UIKeyboardFrameEndUserInfoKey"];
            CGRect frame = [value CGRectValue];
            [UIView animateWithDuration:duration animations:^{
                self.lowerContraint.constant = self.view.frame.size.height - frame.origin.y;;
                [self.view needsUpdateConstraints];
                [self.view layoutIfNeeded];
            }];
        }
    

    【讨论】:

      猜你喜欢
      • 2017-10-23
      • 2013-04-09
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      • 2016-12-26
      相关资源
      最近更新 更多