UIKeyboardWillShowNotification与ios 11 beta 7有关

在iOS 11 beta 7上测试我的应用程序 – 如果我的UIViewController,键盘似乎没有推高内容.

代码看起来像这样(从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];
    }];
}

}

有趣的是 – 当我按下主页按钮(最小化应用程序)并重新打开它(没有杀死它)时 – 布局是固定的.

它似乎是一个iOS 11测试版的bug,但到目前为止我找不到它的任何引用.

很高兴知道其他人是否有这个问题.

解决方法

使用UIKeyboardFrameEndUserInfoKey,因为该键用于包含CGRect的NSValue对象,该CGRect在屏幕坐标中标识键盘的结束帧.不要使用UIKeyboardFrameBeginUserInfoKey.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...