Moving content around when the iOS keyboard shows using UIKeyboardWillChangeFrame
Picture this: you’ve gone and built yourself a beautiful screen for your iOS that has a text field. It looks great. Then… the keyboard shows up and it blocks everything!
“OK,” you say. “No problem. I’ll just copy-paste some code from StackOverflow or a blog post…”
All is well. The view updates when the keyboard shows. Done!
— but then your user complains that the content is getting covered by the keyboard? How could that be!?
Enter custom keyboards. When the custom keyboard it’s the Wild West. The keyboard height changes without warning! Keyboard accessory views! What is a developer to do?
Well, I had this problem too. And I quickly discovered a solution that not only fixed it but at the same time it simplified the keyboard handling process:
Where’s willHide you ask? You don’t need it anymore. If all you want to do is move content when the keyboard shows and hides, why do you care which of the two is happening? All you care is where that top of the keyboard is. And with willChangeFrame you can just get that information and be totally agnostic about whether the keyboard is showing or not.
Use keyboardWillShow and keyboardWillHide if you want to update your view the first time the keyboard shows and when it eventually hides regardless of its size.
You can also use didChangeFrame if for whatever reason you want your changes to happen after the keyboard change updates.

