Gestures are a combination of touch events. An example of gestures is in the default iOS Photo application that allows the user to zoom into and out of a photo using two fingers while “pinching” the photo in and out. Some of the most common gesture event detection code is encapsulated into reusable classes built into the iOS SDK. These classes can be used to detect swipe, pinch, pan, tap, drag, long press, and rotation gestures.
Gesture recognizers must be added to instances of the
UIView class. A single view can have more than
one gesture recognizer. Once a view catches the gesture, that view will
be responsible for passing down the same gesture to other views in the
hierarchy if needed.
Some touch events required by an application might be complicated to process and might require the same event to be detectable in other views in the same application. This introduces the requirements for reusable gesture recognizers. There are six gesture recognizers in iOS SDK 5:
The basic framework for handling a gesture through a built-in gesture recognizer is as follows:
Create an object of the right data type for the gesture recognizer you want.
Add this object as a gesture recognizer to the view that will receive the gesture.
Write a method that is called when the gesture occurs and that takes the action you want.
The method associated as the target method of any gesture recognizer must follow these rules:
It must return
It must either accept ...