作者:双豆儿_668 | 来源:互联网 | 2023-05-19 14:03
IvegotaviewcontrollerlisteningforbothUIKeyboardWillShowNotificationandUIKeyboardWillHideN
I've got a view controller listening for both UIKeyboardWillShowNotification and UIKeyboardWillHideNotification. The handlers for these notifications adjust various parts of the view, which is standard procedure.
我有一个视图控制器监听UIKeyboardWillShowNotification和uikeyboardwillhi。这些通知的处理程序调整视图的各个部分,这是标准过程。
The following code is used to convert the keyboard rect from screen coordinates:
以下代码用于将键盘矩形从屏幕坐标转换为:
CGRect keyboardBounds = [self.view convertRect:[keyboardBoundsValue CGRectValue] fromView:nil];
Again, standard procedure. Unfortunately, there is a critical situation where this conversion fails. Look at what happens when an iPhone is rotated from portrait to landscape while the keyboard is deployed:
同样,标准程序。不幸的是,这种转换失败的情况非常危急。看看当iPhone从竖屏旋转到横屏的时候会发生什么:
1) iOS automatically fires UIKeyboardWillHideNotification; self.interfaceOrientation is reported as portrait; keyboardBounds.height is 216.0. This makes sense. Why? Because the notification handler is given the chance to "clean up" before the view switches to landscape mode.
1) iOS自动触发uikeyboardwillhi;self。interfaceorientation报告为人像;keyboardBounds。高度是216.0。这是有意义的。为什么?因为通知处理程序有机会在视图切换到横向模式之前“清理”。
2) iOS automatically fires UIKeyboardWillShowNotification; self.interfaceOrientation is reported as portrait; keyboardBounds.height is 480.0. This does NOT make sense. Why not? Because the notification handler is going to do its work thinking that the height of the keyboard is 480.0!
2) iOS自动触发UIKeyboardWillShowNotification;self。interfaceorientation报告为人像;keyboardBounds。高度是480.0。这没有道理。为什么不呢?因为通知处理程序将执行它的工作,认为键盘的高度是480.0!
Did Apple drop the ball on this one, or am I doing something wrong?
苹果在这件事上犯了错误,还是我做错了什么?
Please note that listening instead for UIKeyboardDidShowNotification is not a valid solution, because it significantly degrades the user experience. Why? Because animating my changes to the view after the keyboard deployment animation occurs is... well, pretty terrible-looking.
请注意,监听UIKeyboardDidShowNotification不是一个有效的解决方案,因为它会显著降低用户体验。为什么?因为在键盘部署动画发生后,对视图进行动画修改是……嗯,很恐怖的。
Has anyone managed to get autorotation working perfectly while the keyboard is deployed? It seems like an explosion of chaos that Apple has completely overlooked. >:|
当键盘被部署时,有没有人设法使自动旋转工作完美?苹果似乎完全忽略了一场混乱的爆发。>:|
7 个解决方案