<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/preferring-one-gesture-over-another",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Preferring one gesture over another"
}
-->

# Preferring one gesture over another

Use a gesture recognizer delegate object to determine the order in which gestures are recognized in your views.

## Discussion

For any two gesture recognizers involved in a potential conflict, only one needs an associated delegate object, and that object must conform to the [`UIGestureRecognizerDelegate`](/documentation/UIKit/UIGestureRecognizerDelegate) protocol. In your delegate, implement the methods you need for the appropriate resolution. The best way to see how to use these methods is with a few examples.

The following code shows how to recognize tap and double-tap gestures in the same view. The view in this example has two [`UITapGestureRecognizer`](/documentation/UIKit/UITapGestureRecognizer) objects, one of which is configured to require two taps. Normally, the single-tap gesture would always be recognized before the double-tap gesture, but you can use the [`gestureRecognizer(_:shouldRequireFailureOf:)`](/documentation/UIKit/UIGestureRecognizerDelegate/gestureRecognizer(_:shouldRequireFailureOf:)) method to reverse that behavior. The implementation of this method prevents the single-tap gesture from being recognized until after the double-tap gesture recognizer explicitly reaches the failed state, which happens when the touch sequence contains only one tap.

```swift
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, 
         shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
   // Don't recognize a single tap until a double-tap fails.
   if gestureRecognizer == self.tapGesture && 
          otherGestureRecognizer == self.doubleTapGesture {
      return true
   }
   return false
}
```

The following code shows how to recognize a swipe gesture before a pan gesture. In this case, the delegate object is attached to the swipe gesture recognizer and implements the [`gestureRecognizer(_:shouldBeRequiredToFailBy:)`](/documentation/UIKit/UIGestureRecognizerDelegate/gestureRecognizer(_:shouldBeRequiredToFailBy:)) method. The logic of this method prevents the pan gesture from being recognized until the swipe gesture fails.

```swift
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, 
         shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
   // Do not begin the pan until the swipe fails. 
   if gestureRecognizer == self.swipeGesture && 
          otherGestureRecognizer == self.panGesture {
      return true
   }
   return false
}
```

The following code shows an alternative way to configure the dependency between a swipe and a pan gesture. Instead of attaching a delegate object to the swipe gesture, this example attaches the delegate to the pan gesture. Because of the change, the delegate must now implement the [`gestureRecognizer(_:shouldRequireFailureOf:)`](/documentation/UIKit/UIGestureRecognizerDelegate/gestureRecognizer(_:shouldRequireFailureOf:)) method and require the swipe to fail. The end results are the same as those from the previous example.

```swift
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, 
         shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
   if gestureRecognizer == self.panGesture && 
          otherGestureRecognizer == self.swipeGesture {
      return true
   }
   return false
}
```

The ability to attach a delegate to any gesture recognizer lets you create complex dependency chains among your gestures. For more information about regulating gesture recognition, see [`UIGestureRecognizerDelegate`](/documentation/UIKit/UIGestureRecognizerDelegate).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)