问题
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?
Some data...
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)
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.
回答1:
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.
来源:https://stackoverflow.com/questions/46973028/uikeyboardwillchangeframe-and-iphone-x