O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.3. Listening and Reacting to Keyboard Notifications

Problem

You are allowing the user to enter text in your UI by using a component such as a text field or a 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 the keyboard notifications and move your UI components up or down, or completely reshuffle them, so that although the keyboard is obstructing the screen, what is essential to the user is still visible. 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, described further in Recipe 1.19) or a text view (UITextView, described further in Recipe 1.20). 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 on the iPhone ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required