1

In the doc Coordinating Multiple Gesture Recognizers, it says:

UIKit normally allows the recognition of only one gesture at a time on a single view. ... For example, in a view that contains both pan and swipe gesture recognizers, swipes are never recognized.

With that being said, there are also some exceptions. For example, in a view with two UITapGestureRecognizers, the actions of both will get fired.

There's the UIGestureRecognizerDelegate method gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) comes into play externally. But how can the system built-in gesture recognizers, such as UITapGestureRecognizer, decide internally whether or not to work with other recognizers? Or, is there any difference between continuous gesture recognizers and discrete gesture recognizers as regards the behavior?

LShi
  • 1,370
  • 12
  • 28
  • 1
    Hi! Had you tried to see what is the behaviour when you use this delegate: https://developer.apple.com/documentation/uikit/uigesturerecognizer/1620006-shouldrequirefailure (like, if pan fails do the swipe) – Renata Faria Jan 28 '19 at 15:13
  • @RenataFaria Sorry for not reading your comment carefully in the first place! I thought it was a link to the doc of the delegate. I think the method you suggested is the key to the answer. Thank you! – LShi Jan 28 '19 at 15:23

1 Answers1

0

There are two interesting methods of UIGestureRecognizer in the decision process, in which gesture recognizers may be "prevented":

By debugging subclasses of UITapGestureRecognizer, UISwipeGestureRecognizer and UIPanGestureRecognizer, I found that:

  • A "double tap" recognizer will prevent a "single tap" recognizer, but NOT vice versa
  • A pan recognizer will prevent a swipe recognizer

When there are multiple gesture recognizers, the first one that recognizes its gesture will render other recognizers into .failed, by default.

That explains the observed behavior.

LShi
  • 1,370
  • 12
  • 28