UITapGestureRecognizer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 3.2 and later.
Companion guide
Declared in
UITapGestureRecognizer.h
Related sample code

Overview

UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for single or multiple taps. For the gesture to be recognized, the specified number of fingers must tap the view a specified number of times.

Although taps are discrete gestures, they are discrete for each state of the gesture recognizer; thus the associated action message is sent when the gesture begins and is sent for each intermediate state until (and including) the ending state of the gesture. Code that handles tap gestures should therefore test for the state of the gesture, for example:

- (void)handleTap:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded)
    {
        // handling code
    }
}

Action methods handling this gesture may get the location of the gesture as a whole by calling the UIGestureRecognizer method locationInView:; if there are multiple taps, this location is the first tap; if there are multiple touches, this location is the centroid of all fingers tapping the view. Clients may get the location of particular touches in the tap by calling locationOfTouch:inView:; if multiple taps are allowed, this location is that of the first tap.

Tasks

Configuring the Gesture

Properties

numberOfTapsRequired

The number of taps for the gesture to be recognized.

@property(nonatomic) NSUInteger numberOfTapsRequired
Discussion

The default value is 1.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITapGestureRecognizer.h

numberOfTouchesRequired

The number of fingers required to tap for the gesture to be recognized.

@property(nonatomic) NSUInteger numberOfTouchesRequired
Discussion

The default value is 1.

Availability
  • Available in iOS 3.2 and later.
Related Sample Code
Declared In
UITapGestureRecognizer.h