简体   繁体   English

UIKeyboardWillShowNotification与ios 11 beta 7有关

[英]UIKeyboardWillShowNotification issues with ios 11 beta 7

Testing my app on iOS 11 beta 7 - it seems like the keyboard doesn't push up the content if my UIViewController. 在iOS 11 beta 7上测试我的应用程序 - 如果我的UIViewController,键盘似乎没有推高内容。

The code looks like this (working since iOS7): 代码看起来像这样(从iOS7开始工作):

- (void)handleNotification:(NSNotification*)notification {
if (notification.name == UIKeyboardWillShowNotification) {
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    nextButtonALBottomDistance.constant = keyboardSize.height + initialPhoneBottomDistance;
    codeBottomViewALBottomDistance.constant = keyboardSize.height + initialCodeBottomDistance;
    double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    [UIView animateWithDuration:animationDuration animations:^{
        [self.view layoutIfNeeded];
    }];
}
else if (notification.name == UIKeyboardWillHideNotification) {
    nextButtonALBottomDistance.constant = initialPhoneBottomDistance;
    codeBottomViewALBottomDistance.constant = initialCodeBottomDistance;
    double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    [UIView animateWithDuration:animationDuration animations:^{
        [self.view layoutIfNeeded];
    }];
}

} }

Interesting enough - when I press the home button (minimizing the app) and reopening it (without killing it) - the layout is fixed. 有趣的是 - 当我按下主页按钮(最小化应用程序)并重新打开它(没有杀死它)时 - 布局是固定的。

It seems like an iOS 11 beta bug, but I couldn't find any reference to it so far. 它似乎是一个iOS 11测试版的bug,但到目前为止我找不到它的任何引用。

Happy to know if someone else is having this issue. 很高兴知道其他人是否有这个问题。

Use UIKeyboardFrameEndUserInfoKey because that key is for the NSValue object containing a CGRect that identifies an end frame of the keyboard in screen coordinates. 使用UIKeyboardFrameEndUserInfoKey,因为该键用于包含CGRect的NSValue对象,该CGRect在屏幕坐标中标识键盘的结束帧。 Do not use UIKeyboardFrameBeginUserInfoKey . 不要使用UIKeyboardFrameBeginUserInfoKey

If you are using UIKeyboardFrameBeginUserInfoKey key for getting keyboard height, replace it with UIKeyboardFrameEndUserInfoKey to get the correct keyboard height. 如果您使用UIKeyboardFrameBeginUserInfoKey键获取键盘高度,请将其替换为UIKeyboardFrameEndUserInfoKey以获得正确的键盘高度。

In iOS 11, height value of the frame for UIKeyboardFrameBeginUserInfoKey key is 0 because it is a start frame. 在iOS 11中, UIKeyboardFrameBeginUserInfoKey键的帧的高度值为0,因为它是一个起始帧。 To get the actual height we need the end frame, and end frame is returned by UIKeyboardFrameEndUserInfoKey . 为了获得实际高度,我们需要结束帧,并且UIKeyboardFrameEndUserInfoKey返回结束帧。

Please refer Managing the Keyboard documentation : 请参阅管理键盘文档

UIKeyboardFrameBeginUserInfoKey The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard in screen coordinates. UIKeyboardFrameBeginUserInfoKey包含CGRect的NSValue对象的键,用于标识屏幕坐标中键盘的起始帧 These coordinates do not take into account any rotation factors applied to the window's contents as a result of interface orientation changes. 这些坐标不考虑由于界面方向改变而应用于窗口内容的任何旋转因子。 Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it. 因此,您可能需要在使用之前将矩形转换为窗口坐标(使用convertRect:fromWindow:方法)或查看坐标(使用convertRect:fromView:方法)。

UIKeyboardFrameEndUserInfoKey The key for an NSValue object containing a CGRect that identifies the end frame of the keyboard in screen coordinates. UIKeyboardFrameEndUserInfoKey包含CGRect的NSValue对象的键,用于标识屏幕坐标中键盘的结束帧 These coordinates do not take into account any rotation factors applied to the window's contents as a result of interface orientation changes. 这些坐标不考虑由于界面方向改变而应用于窗口内容的任何旋转因子。 Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it. 因此,您可能需要在使用之前将矩形转换为窗口坐标(使用convertRect:fromWindow:方法)或查看坐标(使用convertRect:fromView:方法)。

I ran into this non-movement issue as well. 我也遇到了这个非运动问题。 I suspect that the beginning & end frame were always incorrect, in that they were the same or nearly the same, but was fixed recently in iOS 11 and as such broke a lot of code that didn't truly understand the different between these two frames. 我怀疑开始和结束帧总是不正确的,因为它们是相同或几乎相同,但最近在iOS 11中被修复,因此打破了很多代码,这些代码并没有真正理解这两个帧之间的差异。

Based on the information here https://stackoverflow.com/a/14326257/5282052 根据这里的信息https://stackoverflow.com/a/14326257/5282052

Begin is what the keyboard starts off looking like, which most won't want. 开始是键盘开始看起来像,大多数人不想要的。 End is the result of what the keyboard will look like, which most only are concerned with. 结束是键盘外观的结果,这是大多数人唯一关心的问题。

[[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; [[[user userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue] .size;

Does indeed resolve my issue with a ZERO movement of the scrollview. 确实通过scrollview的ZERO运动解决了我的问题。

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

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