Search code examples
iosuikit

Is UIPanGestureRecognizer discrete or continuous?


I find this doc a bit confusing: https://developer.apple.com/documentation/uikit/uipangesturerecognizer

Specifically, the top of the doc says it's discrete:

A discrete gesture recognizer that interprets panning gestures.

Then the following description says:

A panning gesture is continuous. It begins (UIGestureRecognizer.State.began) when the user moves the minimum number of fingers allowed (minimumNumberOfTouches) enough distance for recognition as a pan. It changes (UIGestureRecognizer.State.changed) when the user moves a finger while pressing with the minimum number of fingers. It ends (UIGestureRecognizer.State.ended) when the user lifts all fingers.

So which is it? discrete or continuous?

My understanding is that discrete recognizer only calls callback action only when it's recognized (e.g. Swipe), but continuous recnogizers calls the callback action when it's moved as well. So pan gesture should be continuous. Am i right?


Solution

  • From the first link DonMag posts in his answer, About the Gesture Recognizer State Machine,

    It explains that discrete gesture recognizers fire/fail once, then reset. Continuous gesture recognizers can go into a loop, returning a state of UIGestureRecognizer.State.changed as the user moves their finger.

    Edit:

    I think @OMGPOP figured out what's going on. It looks like The word "discrete" in the sentence "A discrete gesture recognizer that interprets panning gestures" should be "concrete". That must be a typo.

    Supporting that idea is the fact that the description of the base UIGestureRecognizer class says "UIGestureRecognizer: The base class for concrete gesture recognizers." The UIGestureRecognizer is the abstract parent class of concrete classes like UIPanGestureRecognizer.