Home > Enterprise >  Is UIPanGestureRecognizer discrete or continuous?
Is UIPanGestureRecognizer discrete or continuous?

Time:06-03

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?

CodePudding user response:

It seems to me this is mainly a "terminology" thing.

A UIPanGestureRecognizer is discreet in that it doesn't begin on touch... it enters a state of "possible." It only generates a .began event after the touch has moved enough distance for it to be recognized as a Pan. After that, it is continuous as it sends .changed events as the touch is moved.

You may find it helpful to review these Apple's docs (among others):

Although... you probably only need to know the "down-and-dirty" if you are, in fact, implementing your own gesture recognizer.

CodePudding user response:

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.

I think Don is right that they two sections of the docs are using the word "discrete" in different ways. The bit a pan gesture recognizer that reads "A discrete gesture recognizer that interprets panning gestures" seems like sloppy writing, using the word "discrete" as a term of language rather than the specific type used in the other section.

  • Related