Chapter 5. User interaction

 

This chapter covers

  • Responding to simple touch events
  • Responding to complicated touch gestures
  • Using controls for user interaction

Apps would be static, linear, and boring if the user couldn’t interact with them. In this chapter, we’ll look at three different ways an app can respond to user interaction:

  • Controls are special types of views that are built to receive user interaction. You’ve already seen one type of control in the distance converter app: the text field. In this chapter, you’ll extend the distance converter app to convert kilometers or miles that the user enters in the text fields, by adding buttons and responding to changes in the text fields. Finally, we’ll look at other available controls for receiving user interaction.
  • Next, we’ll look at receiving user interaction in a view via touches. Custom views can respond to touches by overriding relevant view methods. To explore this concept, you’ll build an app with a custom view that changes color when you tap it.
  • We’ll then look at receiving user interaction via gestures. Using gesture recognizers, your app can detect much more complicated movements from touches such as pinching, rotating, long press, or swiping. In this chapter, you’ll build a simple image viewer app that will respond to gestures.

5.1. Controls

5.2. Touching views

5.3. Gesture recognizers

5.4. Summary