2.24. Listening and Reacting to Keyboard Notifications

Problem

You are allowing the user to enter some text in your UI, using some component such as a text field or text view that requires the keyboard’s presence. However, when the keyboard pops up on the screen, it obstructs a good half of your UI, rendering it useless. You want to avoid this situation.

Solution

Listen to keyboard notifications and move your UI components up/down or completely reshuffle your components, so that with the keyboard obstructing the screen, what is essential to the user is still visible to him. For more information about the actual notifications sent by the keyboard, please refer to the Discussion section of this recipe.

Discussion

iOS devices do not have a physical keyboard. They have a software keyboard that pops up whenever the user has to enter some text into something like a text field (UITextField, see Recipe 2.14 for more information) or a text view (UITextView, see Recipe 2.15 for more information). On the iPad, the user can even split the keyboard and move it up and down. These are some of the edge cases that you might want to take care of when designing your user interface. You can work with the UI designers in your company (if you have access to such experts) and let them know about the possibility of the user splitting the keyboard on the iPad. They will need to know about that before making the art and creatives. We will discuss that edge case in this recipe.

Let’s have a look at the keyboard ...

Get iOS 5 Programming Cookbook 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.