Detecting Pan Gesture End Detecting Pan Gesture End objective-c objective-c

Detecting Pan Gesture End


Pan gesture end event can be detected by checking its state with UIGestureRecognizerStateEnded.

Check with the below code .

-(void) panAnim:(UIPanGestureRecognizer*) gestureRecognizer{   if(gestureRecognizer.state == UIGestureRecognizerStateEnded)   {      //All fingers are lifted.   }}

From Apple documentation

A panning gesture is continuous. Itbegins (UIGestureRecognizerStateBegan)when the minimum number of fingersallowed (minimumNumberOfTouches) hasmoved enough to be considered a pan.It changes(UIGestureRecognizerStateChanged) whena finger moves while at least theminimum number of fingers are presseddown. It ends(UIGestureRecognizerStateEnded) whenall fingers are lifted.

Read more about UIPanGestureRecognizer


Pan gesture end event can be detected by checking the it's state with UIGestureRecognizerStateEnded or UIGestureRecognizerStateCancelled or UIGestureRecognizerStateFailed

Check with the below code .

   -(void) panGesture:(UIPanGestureRecognizer*) gestureRecognizer    {     if(gestureRecognizer.state == UIGestureRecognizerStateEnded || gestureRecognizer.state == UIGestureRecognizerStateFailed || gestureRecognizer.state == UIGestureRecognizerStateCancelled)             {                //code what you want.             }     }


Above answers are all correct, this is just an updated one for Swift.

Swift 3:

func panGesture(recognizer: UIPanGestureRecognizer) {    if recognizer.state == .ended {        // Do what you want    }}