Gestures Recognizers – Tap, Pinch/Zoom, Rotate, Swipe, Pan, Long Press

In this post I’ll shows to how to use the Gestures recognizer in IOS development.UIGestureRecognizer is an abstract class, with the following concrete subclasses, one for each type of available recognizer:

  1. UITapGestureRecognizer
  2. UIPinchGestureRecognizer
  3. UIRotationGestureRecognizer
  4. UISwipeGestureRecognizer
  5. UIPanGestureRecognizer
  6. UILongPressGestureRecognizer

Depending on the type of recognizer, there are various behaviors that you can configure. For instance, with the UITapGestureRecognizer, you can specify the number of taps and number of touches. As an example, you could specify that two fingers are required, tapping twice with both fingers.

In response to recognized gestures, an action messages is sent to a target object that you specify. Depending on the type of gesture additional information about the gesture may be available in the action method, for example, the start location of a swipe, or the scale factor of a pinch/zoom.


Gesture Recognizer Examples

Let’s walk through configuration of a few gestures to see how all this works.

Below I’ve defined a recognizer for managing taps, notice how I’ve specified that there are two taps required, with just one touch (finger). The @selector specifies the method that will be called when the gesture is recognized.


Below is a recognizer for two fingers, two taps:

The following gestures recognize swipes up and down:

And finally, two finger pinch:

There are two additional gestures not shown above that you can also tinker with, UIPanGestureRecognizer and UILongPressGestureRecognizer.

Gesture Recognizer Action Methods

For each of the above definitions, below are the associated action methods.

Grab the source code here

Leave a Reply

Your email address will not be published. Required fields are marked *