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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.