iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UIGestureRecognizer Class Reference

Options
Deployment Target:

On This Page
Language:

UIGestureRecognizer

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:

Objective-C

  1. - (void)handleGesture;
  2. - (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;

Swift

  1. func handleGesture() { }
  2. func handleGesture(gestureRecognizer: UIGestureRecognizer) { }

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:

  • cancelsTouchesInView—If a gesture recognizer recognizes its gesture, it unbinds the remaining touches of that gesture from their view (so the window won’t deliver them). The window cancels the previously delivered touches with a (touchesCancelled:withEvent:) message. If a gesture recognizer doesn’t recognize its gesture, the view receives all touches in the multi-touch sequence.

  • delaysTouchesBegan—As long as a gesture recognizer, when analyzing touch events, has not failed recognition of its gesture, the window withholds delivery of touch objects in the UITouchPhaseBegan phase to the attached view. If the gesture recognizer subsequently recognizes its gesture, the view doesn’t receive these touch objects. If the gesture recognizer doesn’t recognize its gesture, the window delivers these objects in an invocation of the view’s touchesBegan:withEvent: method (and possibly a follow-up touchesMoved:withEvent: invocation to inform it of the touches current location).

  • delaysTouchesEnded—As long as a gesture recognizer, when analyzing touch events, has not failed recognition of its gesture, the window withholds delivery of touch objects in the UITouchPhaseEnded phase to the attached view. If the gesture recognizer subsequently recognizes its gesture, the touches are cancelled (in a touchesCancelled:withEvent: message). If the gesture recognizer doesn’t recognize its gesture, the window delivers these objects in an invocation of the view’s touchesEnded:withEvent: method.

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

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:

  • Possible ----> Began ----> [Changed] ----> Cancelled

  • Possible ----> Began ----> [Changed] ----> Ended

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.

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

    Declaration

    Swift

    init(target target: AnyObject?, action action: Selector)

    Objective-C

    - (instancetype nonnull)initWithTarget:(id nullable)target action:(SEL nullable)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.

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

    Declaration

    Swift

    func addTarget(_ target: AnyObject, action action: Selector)

    Objective-C

    - (void)addTarget:(id nonnull)target action:(SEL nonnull)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.

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

    Declaration

    Swift

    func removeTarget(_ target: AnyObject?, action action: Selector)

    Objective-C

    - (void)removeTarget:(id nullable)target action:(SEL nullable)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.

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

    Declaration

    Swift

    func locationInView(_ view: UIView?) -> CGPoint

    Objective-C

    - (CGPoint)locationInView:(UIView * nullable)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.

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

    Declaration

    Swift

    func locationOfTouch(_ touchIndex: Int, inView view: UIView?) -> CGPoint

    Objective-C

    - (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView * nullable)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.

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

    Declaration

    Swift

    func numberOfTouches() -> Int

    Objective-C

    - (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.

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

    Declaration

    Swift

    var state: UIGestureRecognizerState { get }

    Objective-C

    @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:

    1. @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.

  • view view Property

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

    Declaration

    Swift

    var view: UIView? { get }

    Objective-C

    @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.

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

    Declaration

    Swift

    var enabled: Bool

    Objective-C

    @property(nonatomic, getter=isEnabled) BOOL enabled

    Discussion

    Disables a gesture recognizers so it does not receive touches. The default value is YEStrue. If you change this property to NOfalse 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.

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

    Declaration

    Swift

    var cancelsTouchesInView: Bool

    Objective-C

    @property(nonatomic) BOOL cancelsTouchesInView

    Discussion

    When this property is YEStrue (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 NOfalse, the view receives all touches in the multi-touch sequence.

    Availability

    Available in iOS 3.2 and later.

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

    Declaration

    Swift

    var delaysTouchesBegan: Bool

    Objective-C

    @property(nonatomic) BOOL delaysTouchesBegan

    Discussion

    When the value of this property is NOfalse (the default), views analyze touch events in UITouchPhaseBegan and UITouchPhaseMoved in parallel with the receiver. When the value of the property is YEStrue, 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 YEStrue 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.

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

    Declaration

    Swift

    var delaysTouchesEnded: Bool

    Objective-C

    @property(nonatomic) BOOL delaysTouchesEnded

    Discussion

    When the value of this property is YEStrue (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 NOfalse 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.

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).

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

    Declaration

    Objective-C

    - (void)touchesBegan:(NSSet<UITouch *> * nonnull)touches withEvent:(UIEvent * nonnull)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 YEStrue.

    Availability

    Available in iOS 3.2 and later.

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

    Declaration

    Objective-C

    - (void)touchesMoved:(NSSet<UITouch *> * nonnull)touches withEvent:(UIEvent * nonnull)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 YEStrue.

    Availability

    Available in iOS 3.2 and later.

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

    Declaration

    Objective-C

    - (void)touchesEnded:(NSSet<UITouch *> * nonnull)touches withEvent:(UIEvent * nonnull)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 YEStrue.

    Availability

    Available in iOS 3.2 and later.

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

    Declaration

    Objective-C

    - (void)touchesCancelled:(NSSet<UITouch *> * nonnull)touches withEvent:(UIEvent * nonnull)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.

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

    Declaration

    Objective-C

    - (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

    state

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

    Declaration

    Objective-C

    - (void)ignoreTouch:(UITouch * nonnull)touch forEvent:(UIEvent * nonnull)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 YEStrue. This method is intended to be called, not overridden.

    Availability

    Available in iOS 3.2 and later.

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

    Declaration

    Objective-C

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

    Parameters

    preventingGestureRecognizer

    An instance of a subclass of UIGestureRecognizer.

    Return Value

    YEStrue to indicate that preventingGestureRecognizer can block the receiver from recognizing its gesture, otherwise NOfalse.

    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.

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

    Declaration

    Objective-C

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

    Parameters

    preventedGestureRecognizer

    An instance of a subclass of UIGestureRecognizer.

    Return Value

    YEStrue to indicate that the receiver can block preventedGestureRecognizer from recognizing its gesture, otherwise NOfalse.

    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.

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

    Declaration

    Objective-C

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

    Parameters

    otherGestureRecognizer

    An instance of a subclass of UIGestureRecognizer.

    Return Value

    YEStrue to set up the failure requirement; otherwise, NOfalse.

    Discussion

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

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Objective-C

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

    Parameters

    otherGestureRecognizer

    An instance of a subclass of UIGestureRecognizer.

    Return Value

    YEStrue to set up the failure requirement; otherwise, NOfalse.

    Discussion

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

    Availability

    Available in iOS 7.0 and later.

Data Types

  • The current state a gesture recognizer is in.

    Declaration

    Swift

    enum UIGestureRecognizerState : Int { case Possible case Began case Changed case Ended case Cancelled case Failed static var Recognized: UIGestureRecognizerState { get } }

    Objective-C

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

    Constants

    • Possible

      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.

    • Began

      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.

    • Changed

      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.

    • Ended

      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.

    • Cancelled

      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.

    • Failed

      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.

    • Recognized

      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.

    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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.