Chapter 8. Keyboard notifications, animation, and scrolling
This chapter covers
- Getting notifications of system events
- Dismissing the keyboard
- Animating views
- Implementing scrolling
In this chapter, you’ll solve a real-world problem: what do you do when the user taps on an editable text field and the keyboard pops up over the text field, obscuring from view what the user’s typing? How can you recognize when the user taps on the text field and move it so that the user can see what they’re typing?
Along the way, we’ll encounter several important iOS concepts:
- First responders— The first responder is the first view in a scene to receive system events.
- Notifications— Use notifications to listen to messages being broadcast from elsewhere in your app or from other iOS SDK frameworks.
- View animation— Animate any views in the UIKit framework.
- Scroll view— Use the scroll view to animate content.
Imagine that you’ve published what you think is a brilliant app for users to keep records of all the books they own. Great! You submit it to the App Store, and then you start getting comments back . . .
“Unusable!”
“The keyboard covers up the text fields!”
“The keyboard won’t go away!”
Oh no, what’s going on? You open the app on an iPhone SE simulator and immediately see the problem (see figure 8.1).