iOS Developer Library

Developer

UIKit Framework Reference UIGestureRecognizerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIGestureRecognizerDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 3.2 and later.

Delegates of a gesture recognizer—that is, an instance of a concrete subclass of UIGestureRecognizer—adopt the UIGestureRecognizerDelegate protocol to fine-tune an app’s gesture-recognition behavior. The delegates receive messages from a gesture recognizer, and their responses to these messages enable them to affect the operation of the gesture recognizer or to specify a relationship between it and another gesture recognizer, such as allowing simultaneous recognition or setting up a failure requirement.

  • Asks the delegate if a gesture recognizer should begin interpreting touches.

    Declaration

    Swift

    optional func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool

    Objective-C

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

    Parameters

    gestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer. This gesture-recognizer object is about to begin processing touches to determine if its gesture is occurring.

    Return Value

    YEStrue (the default) to tell the gesture recognizer to proceed with interpreting touches, NOfalse to prevent it from attempting to recognize its gesture.

    Discussion

    This method is called when a gesture recognizer attempts to transition out of the UIGestureRecognizerStatePossible state. Returning NOfalse causes the gesture recognizer to transition to the UIGestureRecognizerStateFailed state.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Ask the delegate if a gesture recognizer should receive an object representing a touch.

    Declaration

    Swift

    optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool

    Objective-C

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

    Parameters

    gestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer.

    touch

    A UITouch object from the current multi-touch sequence.

    Return Value

    YEStrue (the default) to allow the gesture recognizer to examine the touch object, NOfalse to prevent the gesture recognizer from seeing this touch object.

    Discussion

    This method is called before touchesBegan:withEvent: is called on the gesture recognizer for a new touch.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Asks the delegate if two gesture recognizers should be allowed to recognize gestures simultaneously.

    Declaration

    Swift

    optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool

    Objective-C

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

    Parameters

    gestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer. This is the object sending the message to the delegate.

    otherGestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer.

    Return Value

    YEStrue to allow both gestureRecognizer and otherGestureRecognizer to recognize their gestures simultaneously. The default implementation returns NOfalse—no two gestures can be recognized simultaneously.

    Discussion

    This method is called when recognition of a gesture by either gestureRecognizer or otherGestureRecognizer would block the other gesture recognizer from recognizing its gesture. Note that returning YEStrue is guaranteed to allow simultaneous recognition; returning NOfalse, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer's delegate may return YEStrue.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Asks the delegate if a gesture recognizer should require another gesture recognizer to fail.

    Declaration

    Swift

    optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOfGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool

    Objective-C

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

    Parameters

    gestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer. This is the object sending the message to the delegate.

    otherGestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer.

    Return Value

    YEStrue to set up a dynamic failure requirement between gestureRecognizer and otherGestureRecognizer. The default implementation returns NOfalsegestureRecognizer doesn’t require otherGestureRecognizer to fail.

    Discussion

    This method is called once per attempt to recognize, so failure requirements can be determined lazily and may be set up between recognizers across view hierarchies. Note that returning YEStrue is guaranteed to set up the failure requirement; returning NOfalse, on the other hand, isn’t guaranteed to prevent or remove a failure requirement because otherGestureRecognizer might make itself a failure requirement by using its own subclass or delegate methods.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Asks the delegate if a gesture recognizer should be required to fail by another gesture recognizer.

    Declaration

    Swift

    optional func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailByGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool

    Objective-C

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

    Parameters

    gestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer. This is the object sending the message to the delegate.

    otherGestureRecognizer

    An instance of a subclass of the abstract base class UIGestureRecognizer.

    Return Value

    YEStrue to set up a dynamic failure requirement between gestureRecognizer and otherGestureRecognizer. The default implementation returns NOfalsegestureRecognizer isn’t required to fail by otherGestureRecognizer.

    Discussion

    This method is called once per attempt to recognize, so failure requirements can be determined lazily and may be set up between recognizers across view hierarchies. Note that returning YEStrue is guaranteed to set up the failure requirement; returning NOfalse, on the other hand, isn’t guaranteed to prevent or remove a failure requirement because otherGestureRecognizer might make itself a failure requirement by using its own subclass or delegate methods.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.