UIKeyboardWillShowNotification issues with 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测试版错误,但到目前为止我找不到任何参考。

很高兴知道其他人是否遇到此问题。

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

如果您使用 UIKeyboardFrameBeginUserInfoKey 键来获取键盘高度,请将其替换为UIKeyboardFrameEndUserInfoKey以获得正确的键盘高度。

在 iOS 11 中,UIKeyboardFrameBeginUserInfoKey键的帧高度值为 0,因为它是开始帧。为了获得实际高度,我们需要结束框架,结束框架由UIKeyboardFrameEndUserInfoKey返回。

请参阅管理键盘文档:

UIKeyboardFrameBeginUserInfoKeyThe 包含 CGRect,以屏幕坐标标识键盘的起始帧。 这些坐标不考虑 考虑应用的任何轮换系数 结果到窗口的内容 的界面方向更改。 因此,您可能需要转换 矩形到窗口坐标(使用 转换矩形:从窗口:方法)或 查看坐标(使用 convertRect:fromView: method) 之前 使用它。

UIKeyboardFrameEndUserInfoKeyKey 对于包含 CGRect,以屏幕坐标标识键盘的结束帧。 这些坐标不考虑 考虑应用的任何轮换系数 结果到窗口的内容 的界面方向更改。 因此,您可能需要转换 矩形到窗口坐标(使用 转换矩形:从窗口:方法)或 查看坐标(使用 convertRect:fromView: method) 之前 使用它。

我也遇到了这个非运动问题。 我怀疑开始和结束帧总是不正确的,因为它们相同或几乎相同,但最近在iOS 11中得到了修复,因此破坏了许多代码,这些代码并没有真正理解这两个帧之间的差异。

基于此处的信息 https://stackoverflow.com/a/14326257/5282052

开始是键盘开始时的样子,大多数人不想要。 End 是键盘外观的结果,大多数人只关心这一点。

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

确实解决了滚动视图零移动的问题。

最新更新