Chapter 5. Touch Events

WHAT'S IN THIS CHAPTER?

  • How to handle touch events

  • How to create and handle gestures

  • How to simplify gesture recognition with the use of UIGestureRecognizer

With traditional desktop user interaction, events are initiated by the use of the keyboard or mouse. With iOS 4, touch and motion events are delivered to your application. The manager of these events is the UIApplication object and the actual event is a UIEvent object. The most common event that you will track in your application is the touch event interacting with views.

The UITouch sequence begins as soon as the user places a finger or fingers on the screen, and ends when the last finger has been removed from the screen. The location of the finger or fingers resolves itself to a touch point or CGPoint data value.

Touch events can be multi-fingered, as in the case of a pinch, when you zoom in or out on a photo. Single-fingered events can be the tap, the touch and hold, and the drag and swipe.

In this chapter you will observe two techniques of event handling that involve touches: The first uses touchesBegan, touchesMoved, touchesEnded and touchesCancelled, which are defined by iOS 4. The second, gesture recognition, uses the UIGestureRecognizer, which allows the customization of gestures in addition to the standard set.

TOUCH EVENT HANDLING

A touch event is a UIEvent of the type UIEventTypeTouches. The UITouch object represents the touches themselves and contains the following information:

  • locationInView — Coordinates ...

Get Professional iPhone® and iPad™ Application Development 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.