简体   繁体   English

调整iOS硬件键盘的视框

[英]Adjusting view frame for iOS hardware keyboard

I followed the instructions here to adjust my view with the iOS keyboard. 我按照此处的说明使用iOS键盘调整了视图。 https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

This doesn't work with a hardware keyboard. 这不适用于硬件键盘。 When a text view is active the iOS keyboard is not shown but the example code still returns the full height of the keyboard. 当文本视图处于活动状态时,未显示iOS键盘,但示例代码仍返回键盘的完整高度。 In my case just the input accessory view is shown on the screen. 在我的情况下,仅输入的附件视图显示在屏幕上。

How do I detect this case and adjust my view for only the input accessory view? 如何检测到这种情况并仅调整输入附件视图的视图?

您可以将键盘的框架与当前窗口相交,如我的答案在这里https://stackoverflow.com/a/36553555/1049134

Came across the same issue. 遇到了同样的问题。 Looks like the iOS keyboard is completely instantiated and just moved out of the view partial when a hardware keyboard is attached. 看起来,iOS键盘已完全实例化,并且在连接硬件键盘后仅移出了部分视图。 Therefore the size of the keyboard is right. 因此,键盘的大小是正确的。 It is just not completely shown. 它只是没有完全显示。

After examining the notifications I solved it with calculating the visible keyboard height myself. 检查通知后,我自己计算了可见的键盘高度来解决了该问题。 In my example I am listening to UIKeyboardWillShowNotification, UIKeyboardWillChangeFrameNotification and UIKeyboardWillHideNotification. 在我的示例中,我正在听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];
        }];
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM