Resizing for the Keyboard
When the keyboard comes up, it might cover one or more of the input fields. A scroll view lets you move the fields into view so the user can see where he or she can input text. All you have to do is resize the scroll view so it is above the keyboard. The scroll view becomes smaller, but the content size does not change and the user can scroll the form view, and therefore, the fields.
When the keyboard opens and closes, iOS uses the built-in NSNotificationCenter
to send events. You add code to listen for the correct events and change the size of the scroll view as needed. Doing this takes three steps:
1. Add methods responding to keyboard open-and-close events.
2. Register for keyboard open-and-close notifications when ...
Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.