UIKeyboardWillChangeFrame 和 iPhone X [英] UIKeyboardWillChangeFrame and iPhone X

查看:15
本文介绍了UIKeyboardWillChangeFrame 和 iPhone X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里尝试使用模拟器,似乎在使用 UIKeyboardWillChangeFrame 侦听更改时返回的框架对于 iPhone X 是不正确的.具体来说,框架似乎比实际高一点(明显)在屏幕上.我会说返回的框架高约 20 点.

Trying with simulator here, and it seems that the frame returned when listening for changes with UIKeyboardWillChangeFrame is incorrect for iPhone X. Specifically the frame seems to be a bit taller than it actually is (visibly) on screen. I'd say the returned frame is about 20 points taller.

我是不是忘记了一些明显的东西?

Did I forget something obvious?

一些数据...

iPhone X 和 iPhone 8 的纵向宽度相同,因此横向高度相同;375 分.( https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions )

The iPhone X and iPhone 8 have the same width in portrait, which makes it the same height in landscape; 375 points. ( https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions )

                    // iPhone X values:
//                  keyboardChange, frame: (0.0, 375.0, 812.0, 171.0)
//                  keyboardChange, frame: (0.0, 204.0, 812.0, 171.0)
                    // iPhone 8 values:
//                  keyboardChange, frame: (0.0, 375.0, 667.0, 162.0) (keyboard closed)
//                  keyboardChange, frame: (0.0, 213.0, 667.0, 162.0) (keyboard opened)

我们可以看到,在 iPhone X 上打开键盘时的 Y 值较小,这导致我们将我们自己的任何 UI 元素在屏幕上对齐.即它们不会在键盘顶部完美对齐.这是我当前的问题,我假设所有其他应用程序也会遇到这个问题.

We can see that the Y value when keyboard is opened on the iPhone X is smaller, which leads us to align any of our own UI elements higher on screen. Ie they will not align perfectly on top of the keyboard. Which is my current problem, and I assume all other apps doing that will also suffer from this problem.

推荐答案

我的问题没有包含足够的信息来直接解决问题,我现在明白了.正如我在上面的评论中所写的那样,这个问题本身并不是 iPhone X 的问题,但是如果您想使用 UIKeyboardWillChangeFrame 通知提供的框架将 UI 元素放在键盘顶部,您必须确保限制在超级视图的最底部,而不是安全区域底部,这在我添加安全区域支持时发生在我的故事板中.

My question did not contain enough info to be able to directly attack the problem, I see now. As I wrote in my comment above, the issue was not a problem with iPhone X per se but if you want to put a UI element on top of the keyboard using the frame supplied with the UIKeyboardWillChangeFrame notification, you must make sure to constrain to the extreme bottom of the superview, and not to the safe area bottom, which had happened in my storyboard as I added safe area support.

这篇关于UIKeyboardWillChangeFrame 和 iPhone X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆