Learn how to use a delegate object to allow detection of more than one gesture at a time.
There are times when it makes sense to allow the simultaneous recognition of multiple gestures. Figure 1 shows an app that allows users to drag, scale, and rotate three colored views onscreen. Each view maintains its own unique set of pan, pinch, and rotate gesture recognizers, and it is possible for all three of a view’s gesture recognizers to perform their actions simultaneously.
To allow a gesture recognizer to operate simultaneously with other gestures, assign a delegate object that implements the
gesture method to it. UIKit calls this method for pairs of gesture recognizers attached to the same view. Returning true allows both gestures to process events simultaneously.
Listing 1 shows the
gesture method from the app shown in Figure 1. This method returns true when the gesture recognizers are attached to the same view. If the gesture recognizers are attached to different views, or if one of the objects is a long press gesture recognizer, this method returns false.
For more information about the sample, see Handling Touches Using Responder Methods and Gesture Recognizers.