UIGestureRecognizer Class Reference

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

Overview

UIGestureRecognizer is an abstract base class for concrete gesture-recognizer classes. A gesture-recognizer object—or, simply, a gesture recognizer—decouples the logic for recognizing a gesture and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.

The concrete subclasses of UIGestureRecognizer are the following:

The UIGestureRecognizer class defines a set of common behaviors that can be configured for all concrete gesture recognizers. It can also communicate with its delegate (an object that adopts the UIGestureRecognizerDelegate protocol), thereby enabling finer-grained customization of some behaviors.

A gesture recognizer operates on touches hit-tested to a specific view and all of that view’s subviews. It thus must be associated with that view. To make that association you must call the UIView method addGestureRecognizer:. A gesture recognizer doesn’t participate in the view’s responder chain.

A gesture recognizer has one or more target-action pairs associated with it. If there are multiple target-action pairs, they are discrete, and not cumulative. Recognition of a gesture results in the dispatch of an action message to a target for each of the associated pairs. The action methods invoked must conform to one of the following signatures:

- (void)handleGesture;
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;

Methods conforming to the latter signature permit the target in some cases to query the gesture recognizer sending the message for additional information. For example, the target could ask a UIRotationGestureRecognizer object for the angle of rotation (in radians) since the last invocation of the action method for this gesture. Clients of gesture recognizers can also ask for the location of a gesture by calling locationInView: or locationOfTouch:inView:.

The gesture interpreted by a gesture recognizer can be either discrete or continuous. A discrete gesture, such as a double tap, occurs but once in a multi-touch sequence and results in a single action sent. However, when a gesture recognizer interprets a continuous gesture such as a rotation gesture, it sends an action message for each incremental change until the multi-touch sequence concludes.

A window delivers touch events to a gesture recognizer before it delivers them to the hit-tested view attached to the gesture recognizer. Generally, if a gesture recognizer analyzes the stream of touches in a multi-touch sequence and doesn’t recognize its gesture, the view receives the full complement of touches. If a gesture recognizer recognizes its gesture, the remaining touches for the view are cancelled. The usual sequence of actions in gesture recognition follows a path determined by default values of the cancelsTouchesInView, delaysTouchesBegan, delaysTouchesEnded properties:

Note that "recognize” in the above descriptions doesn’t necessarily equate to a transition to the Recognized state.

Usage Special Considerations

To determine whether a class is available at runtime in a given iOS release, you typically check whether the class is nil. Unfortunately, this test is not cleanly accurate for UIGestureRecognizer. Although this class was publicly available starting with iOS 3.2, it was in development a short period prior to that. Although the class exists in an earlier release, use of it and other gesture-recognizer classes are not supported in that earlier release. You should not attempt to use instances of those classes.

To determine at runtime whether you can use gesture recognizers in your app, test whether the class exists and, if it does, allocate an instance and check if it responds to the selector locationInView:. This method was not added to the class until iOS 3.2. The code might look like the following:

UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(myAction:)];
 
if (![gestureRecognizer respondsToSelector:@selector(locationInView:)]) {
    [gestureRecognizer release];
    gestureRecognizer = nil;
}
// do something else if gestureRecognizer is nil

Subclassing Notes

You may create a subclass of UIGestureRecognizer that recognizes a distinctive gesture—for example, a “check mark” gesture. If you are going to create such a concrete gesture recognizer, be sure to import the UIGestureRecognizerSubclass.h header file. This header file declares all the methods and properties a subclass must either override, call, or reset.

Gesture recognizers operate within a predefined state machine, transitioning to subsequent states as they handle multi-touch events. The states and their possible transitions differ for continuous and discrete gestures. All gesture recognizers begin a multi-touch sequence in the Possible state (UIGestureRecognizerStatePossible). Discrete gestures transition from Possible to either Recognized (UIGestureRecognizerStateRecognized) or Failed (UIGestureRecognizerStateFailed), depending on whether they successfully interpret the gesture or not. If the gesture recognizer transitions to Recognized, it sends its action message to its target.

For continuous gestures, the state transitions a gesture recognizer might make are more numerous, as indicated in the following diagram:

The Changed state is optional and may occur multiple times before the Cancelled or Ended state is reached. The gesture recognizer sends action messages at each state transition. Thus for a continuous gesture such as a pinch, action messages are sent as the two fingers move toward or away from each other. The enum constants representing these states are of type UIGestureRecognizerState. (Note that the constants for Recognized and Ended states are synonymous.)

Subclasses must set the state property to the appropriate value when they transition between states.

Methods to Override

The methods that subclasses must override are described in “Methods For Subclasses.” Subclasses must also periodically reset the state property (as described above) and may call the ignoreTouch:forEvent: method.

Special Considerations

The state property is declared in UIGestureRecognizer.h as being read-only. This property declaration is intended for clients of gesture recognizers. Subclasses of UIGestureRecognizer must import UIGestureRecognizerSubclass.h. This header file contains a redeclaration of state that makes it read-write.

Tasks

Initializing a Gesture Recognizer

Adding and Removing Targets and Actions

Getting the Touches and Location of a Gesture

Getting the Recognizer’s State and View

Canceling and Delaying Touches

Specifying Dependencies Between Gesture Recognizers

Setting and Getting the Delegate

Methods For Subclasses

The UIGestureRecognizerSubclass.h header file contains a class extension that declares methods intended to be called or overridden only by subclasses of UIGestureRecognizer. Clients that merely use concrete subclasses of UIGestureRecognizer must never call these methods (except for those noted).

Properties

cancelsTouchesInView

A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.

@property(nonatomic) BOOL cancelsTouchesInView
Discussion

When this property is YES (the default) and the receiver recognizes its gesture, the touches of that gesture that are pending are not delivered to the view and previously delivered touches are cancelled through a touchesCancelled:withEvent: message sent to the view. If a gesture recognizer doesn’t recognize its gesture or if the value of this property is NO, the view receives all touches in the multi-touch sequence.

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

delaysTouchesBegan

A Boolean value determining whether the receiver delays sending touches in a begin phase to its view.

@property(nonatomic) BOOL delaysTouchesBegan
Discussion

When the value of this property is NO (the default), views analyze touch events in UITouchPhaseBegan and UITouchPhaseMoved in parallel with the receiver. When the value of the property is YES, the window suspends delivery of touch objects in the UITouchPhaseBegan phase to the view. If the gesture recognizer subsequently recognizes its gesture, these touch objects are discarded. If the gesture recognizer, however, does not recognize its gesture, the window delivers these objects to the view in a touchesBegan:withEvent: message (and possibly a follow-up touchesMoved:withEvent: message to inform it of the touches’ current locations). Set this property to YES to prevent views from processing any touches in the UITouchPhaseBegan phase that may be recognized as part of this gesture.

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

delaysTouchesEnded

A Boolean value determining whether the receiver delays sending touches in a end phase to its view.

@property(nonatomic) BOOL delaysTouchesEnded
Discussion

When the value of this property is YES (the default) and the receiver is analyzing touch events, the window suspends delivery of touch objects in the UITouchPhaseEnded phase to the attached view. If the gesture recognizer subsequently recognizes its gesture, these touch objects are cancelled (via a touchesCancelled:withEvent: message). If the gesture recognizer does not recognize its gesture, the window delivers these objects in an invocation of the view’s touchesEnded:withEvent: method. Set this property to NO to have touch objects in the UITouchPhaseEnded delivered to the view while the gesture recognizer is analyzing the same touches.

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

delegate

The delegate of the gesture recognizer.

@property(nonatomic, assign) id<UIGestureRecognizerDelegate> delegate
Discussion

The gesture recognizer maintains a weak reference to its delegate. The delegate must adopt the UIGestureRecognizerDelegate protocol and implement one or more of its methods.

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

enabled

A Boolean property that indicates whether the gesture recognizer is enabled.

@property(nonatomic, getter=isEnabled) BOOL enabled
Discussion

Disables a gesture recognizers so it does not receive touches. The default value is YES. If you change this property to NO while a gesture recognizer is currently recognizing a gesture, the gesture recognizer transitions to a cancelled state.

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

state

The current state of the gesture recognizer. (read-only)

@property(nonatomic, readonly) UIGestureRecognizerState state
Discussion

The possible states a gesture recognizer can be in are represented by the constants of type UIGestureRecognizerState. Some of these states are not applicable to discrete gestures. The read-only version of the state property is intended for clients of a gesture-recognizer class and not subclasses.

Special Considerations

Subclasses of UIGestureRecognizer must use a read-write version of the state property. They get this redeclaration when they import the UIGestureRecognizerSubclass.h header file:

@property(nonatomic,readwrite) UIGestureRecognizerState state;

Recognizers for discrete gestures transition from UIGestureRecognizerStatePossible to UIGestureRecognizerStateFailed or UIGestureRecognizerStateRecognized. Recognizers for continuous gesture transition from UIGestureRecognizerStatePossible to these phases in the given order: UIGestureRecognizerStateBegan, UIGestureRecognizerStateChanged, and UIGestureRecognizerStateEnded. If, however, they receive a cancellation touch, they should transition to UIGestureRecognizerStateCancelled. If recognizers for continuous gestures can’t interpret a multi-touch sequence as their gesture, they transition to UIGestureRecognizerStateFailed.

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

view

The view the gesture recognizer is attached to. (read-only)

@property(nonatomic, readonly) UIView *view
Discussion

You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: method.

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

Instance Methods

addTarget:action:

Adds a target and an action to a gesture-recognizer object.

- (void)addTarget:(id)target action:(SEL)action
Parameters
target

An object that is a recipient of action messages sent by the receiver when the represented gesture occurs. nil is not a valid value.

action

A selector identifying a method of a target to be invoked by the action message. NULL is not a valid value.

Discussion

You may call this method multiple times to specify multiple target-action pairs. However, if you request to add a target-action pair that has already been added, then the request is ignored.

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

canBePreventedByGestureRecognizer:

Overridden to indicate that the specified gesture recognizer can prevent the receiver from recognizing a gesture.

- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
Parameters
preventingGestureRecognizer

An instance of a subclass of UIGestureRecognizer.

Return Value

YES to indicate that preventingGestureRecognizer can block the receiver from recognizing its gesture, otherwise NO.

Discussion

Overriding these methods enables the same behavior as implementing the UIGestureRecognizerDelegate methods gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:. However, by overriding them, subclasses can define class-wide prevention rules. For example, a UITapGestureRecognizer object never prevents another UITapGestureRecognizer object with a higher tap count.

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

canPreventGestureRecognizer:

Overridden to indicate that the receiver can prevent the specified gesture recognizer from recognizing its gesture.

- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
Parameters
preventedGestureRecognizer

An instance of a subclass of UIGestureRecognizer.

Return Value

YES to indicate that the receiver can block preventedGestureRecognizer from recognizing its gesture, otherwise NO.

Discussion

Overriding these methods enables the same behavior as implementing the UIGestureRecognizerDelegate methods gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:. However, by overriding them, subclasses can define class-wide prevention rules. For example, a UITapGestureRecognizer object never prevents another UITapGestureRecognizer object with a higher tap count.

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

ignoreTouch:forEvent:

Tells the gesture recognizer to ignore a specific touch of the given event.

- (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event
Parameters
touch

A UITouch object that is part of the current multi-touch sequence and associated with event.

event

A UIEvent object that includes a reference to touch.

Discussion

If a touch isn't part of this gesture you may pass it to this method, causing it to be ignored. UIGestureRecognizer does not cancel ignored touches on the associated view even if cancelsTouchesInView is YES. This method is intended to be called, not overridden.

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

initWithTarget:action:

Initializes an allocated gesture-recognizer object with a target and an action selector.

- (id)initWithTarget:(id)target action:(SEL)action
Parameters
target

An object that is the recipient of action messages sent by the receiver when it recognizes a gesture. nil is not a valid value.

action

A selector that identifies the method implemented by the target to handle the gesture recognized by the receiver. The action selector must conform to the signature described in the class overview. NULL is not a valid value.

Return Value

An initialized instance of a concrete UIGestureRecognizer subclass or nil if an error occurred in the attempt to initialize the object.

Discussion

This method is the designated initializer. After creating the gesture recognizer, you may associate other target-action pairs with it by calling addTarget:action:.

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

locationInView:

Returns the point computed as the location in a given view of the gesture represented by the receiver.

- (CGPoint)locationInView:(UIView *)view
Parameters
view

A UIView object on which the gesture took place. Specify nil to indicate the window.

Return Value

A point in the local coordinate system of view that identifies the location of the gesture. If nil is specified for view, the method returns the gesture location in the window’s base coordinate system.

Discussion

The returned value is a generic single-point location for the gesture computed by the UIKit framework. It is usually the centroid of the touches involved in the gesture. For objects of the UISwipeGestureRecognizer and UITapGestureRecognizer classes, the location returned by this method has a significance special to the gesture. This significance is documented in the reference for those classes.

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

locationOfTouch:inView:

Returns the location of one of the gesture’s touches in the local coordinate system of a given view.

- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view
Parameters
touchIndex

The index of a UITouch object in a private array maintained by the receiver. This touch object represents a touch of the current gesture.

view

A UIView object on which the gesture took place. Specify nil to indicate the window.

Return Value

A point in the local coordinate system of view that identifies the location of the touch. If nil is specified for view, the method returns the touch location in the window’s base coordinate system.

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

numberOfTouches

Returns the number of touches involved in the gesture represented by the receiver.

- (NSUInteger)numberOfTouches
Return Value

The number of UITouch objects in a private array maintained by the receiver. Each of these objects represents a touch in the current gesture.

Discussion

Using the value returned by this method in a loop, you can ask for the location of individual touches using the locationOfTouch:inView: method.

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

removeTarget:action:

Removes a target and an action from a gesture-recognizer object.

- (void)removeTarget:(id)target action:(SEL)action
Parameters
target

An object that currently is a recipient of action messages sent by the receiver when the represented gesture occurs. Specify nil if you want to remove all targets from the receiver.

action

A selector identifying a method of a target to be invoked by the action message. Specify NULL if you want to remove all actions from the receiver.

Discussion

Calling this method removes the specified target-action pair. Passing nil for target matches all targets and passing NULL for action matches all actions.

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

requireGestureRecognizerToFail:

Creates a dependency relationship between the receiver and another gesture recognizer.

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
Parameters
otherGestureRecognizer

Another gesture-recognizer object (an instance of a subclass of UIGestureRecognizer).

Discussion

This method creates a relationship with another gesture recognizer that delays the receiver’s transition out of UIGestureRecognizerStatePossible. The state that the receiver transitions to depends on what happens with otherGestureRecognizer:

An example where this method might be called is when you want a single-tap gesture require that a double-tap gesture fail.

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

reset

Overridden to reset internal state when a gesture recognition attempt completes.

- (void)reset
Discussion

The runtime calls this method after the gesture-recognizer state has been set to UIGestureRecognizerStateEnded, UIGestureRecognizerStateRecognized, UIGestureRecognizerStateCancelled, or UIGestureRecognizerStateFailed—in other words, any of the terminal states for a gesture recognition attempt. Subclasses should reset any internal state in preparation for a new attempt at gesture recognition. After this method is called, the gesture recognizer receives no further updates for touches that have begun but haven't ended.

Availability
  • Available in iOS 3.2 and later.
See Also
Declared In
UIGestureRecognizerSubclass.h

shouldBeRequiredToFailByGestureRecognizer:

Overridden to indicate that the receiver should be required to fail by the specified gesture recognizer.

- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
Parameters
otherGestureRecognizer

An instance of a subclass of UIGestureRecognizer.

Return Value

YES to set up the failure requirement; otherwise, NO.

Discussion

Overriding this method allows a subclass to define a class-wide failure requirement.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIGestureRecognizerSubclass.h

shouldRequireFailureOfGestureRecognizer:

Overridden to indicate that the receiver requires the specified gesture recognizer to fail.

- (BOOL)shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
Parameters
otherGestureRecognizer

An instance of a subclass of UIGestureRecognizer.

Return Value

YES to set up the failure requirement; otherwise, NO.

Discussion

Overriding this method allows a subclass to define a class-wide failure requirement.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIGestureRecognizerSubclass.h

touchesBegan:withEvent:

Sent to the receiver when one or more fingers touch down in the associated view.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Parameters
touches

A set of UITouch instances in the event represented by event that represent the touches in the UITouchPhaseBegan phase.

event

A UIEvent object representing the event to which the touches belong.

Discussion

This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseBegan phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.

If the gesture recognizer is interpreting a continuous gesture, it should set its state to UIGestureRecognizerStateBegan upon receiving this message. If at any point in its handling of the touch objects the gesture recognizer determines that the multi-touch event sequence is not its gesture, it should set it state to UIGestureRecognizerStateCancelled.

Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the attached view instance to YES.

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

touchesCancelled:withEvent:

Sent to the receiver when a system event (such as a low-memory warning) cancels a touch event.

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
Parameters
touches

A set of UITouch instances in the event represented by event that represent the touches in the UITouchPhaseCancelled phase.

event

A UIEvent object representing the event to which the touches belong.

Discussion

This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseCancelled phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.

Upon receiving this message, the gesture recognizer for a continuous gesture should set its state to UIGestureRecognizerStateCancelled; a gesture recognizer for a discrete gesture should set its state to UIGestureRecognizerStateFailed.

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

touchesEnded:withEvent:

Sent to the receiver when one or more fingers lift from the associated view.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Parameters
touches

A set of UITouch instances in the event represented by event that represent the touches in the UITouchPhaseEnded phase.

event

A UIEvent object representing the event to which the touches belong.

Discussion

This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseEnded phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.

If the gesture recognizer is interpreting a continuous gesture, it should set its state to UIGestureRecognizerStateEnded upon receiving this message. If it is interpreting a discrete gesture, it should set its state to UIGestureRecognizerStateRecognized. If at any point in its handling of the touch objects the gesture recognizer determines that the multi-touch event sequence is not its gesture, it should set it state to UIGestureRecognizerStateCancelled.

Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the attached view instance to YES.

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

touchesMoved:withEvent:

Sent to the receiver when one or more fingers move in the associated view.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
Parameters
touches

A set of UITouch instances in the event represented by event that represent touches in the UITouchPhaseMoved phase.

event

A UIEvent object representing the event to which the touches belong.

Discussion

This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseMoved phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.

If the gesture recognizer is interpreting a continuous gesture, it should set its state to UIGestureRecognizerStateChanged upon receiving this message. If at any point in its handling of the touch objects the gesture recognizer determines that the multi-touch event sequence is not its gesture, it should set it state to UIGestureRecognizerStateCancelled .

Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the attached view instance to YES.

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

Constants

UIGestureRecognizerState

The current state a gesture recognizer is in.

typedef enum {
   UIGestureRecognizerStatePossible,
   
   UIGestureRecognizerStateBegan,
   UIGestureRecognizerStateChanged,
   UIGestureRecognizerStateEnded,
   UIGestureRecognizerStateCancelled,
   
   UIGestureRecognizerStateFailed,
   
   UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
} UIGestureRecognizerState;
Constants
UIGestureRecognizerStatePossible

The gesture recognizer has not yet recognized its gesture, but may be evaluating touch events. This is the default state.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

UIGestureRecognizerStateBegan

The gesture recognizer has received touch objects recognized as a continuous gesture. It sends its action message (or messages) at the next cycle of the run loop.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

UIGestureRecognizerStateChanged

The gesture recognizer has received touches recognized as a change to a continuous gesture. It sends its action message (or messages) at the next cycle of the run loop.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

UIGestureRecognizerStateEnded

The gesture recognizer has received touches recognized as the end of a continuous gesture. It sends its action message (or messages) at the next cycle of the run loop and resets its state to UIGestureRecognizerStatePossible.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

UIGestureRecognizerStateCancelled

The gesture recognizer has received touches resulting in the cancellation of a continuous gesture. It sends its action message (or messages) at the next cycle of the run loop and resets its state to UIGestureRecognizerStatePossible.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

UIGestureRecognizerStateFailed

The gesture recognizer has received a multi-touch sequence that it cannot recognize as its gesture. No action message is sent and the gesture recognizer is reset to UIGestureRecognizerStatePossible.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

UIGestureRecognizerStateRecognized

The gesture recognizer has received a multi-touch sequence that it recognizes as its gesture. It sends its action message (or messages) at the next cycle of the run loop and resets its state to UIGestureRecognizerStatePossible.

Available in iOS 3.2 and later.

Declared in UIGestureRecognizer.h.

Discussion

Gesture recognizers recognize a discrete event such as a tap or a swipe but don’t report changes within the gesture. In other words, discrete gestures don’t transition through the Began and Changed states and they can’t fail or be cancelled.

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