UIKeyboardWillShowNotification issues with ios 11 beta 7

╄→尐↘猪︶ㄣ 提交于 2019-12-04 05:57:08
Nirav Kotecha

Use UIKeyboardFrameEndUserInfoKey because that key is for the NSValue object containing a CGRect that identifies an end frame of the keyboard in screen coordinates. Do not use UIKeyboardFrameBeginUserInfoKey.

If you are using UIKeyboardFrameBeginUserInfoKey key for getting keyboard height, replace it with UIKeyboardFrameEndUserInfoKey to get the correct keyboard height.

In iOS 11, height value of the frame for UIKeyboardFrameBeginUserInfoKey key is 0 because it is a start frame. To get the actual height we need the end frame, and end frame is returned by 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. 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.

UIKeyboardFrameEndUserInfoKey The key for an NSValue object containing a CGRect that identifies the end frame of the keyboard in screen coordinates. 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.

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.

Based on the information here 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;

Does indeed resolve my issue with a ZERO movement of the scrollview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!