I've got a view and I applied a UIPanGestureRecogniser to this view:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAnim:)]; [sliderView addGestureRecognizer:panGesture]; [panGesture release];
I can detect and process the gesture just fine. However, I wish to initiate another method once the gesture has ended.
I know there are two methods that allow this kind of detection. touchesEnded
and touchesCancelled
however, I've found that touchesCancelled
gets called as soon as the touch becomes a gesture i.e. I move my finger enough to warrant a gesture call and touchesEnded
rarely, if ever, gets called.
I want to be able to pan left / right and then initiate another function call upon gesture ending. How do I do this?
A pan gesture occurs any time the user moves one or more fingers around the screen. A screen-edge pan gesture is a specialized pan gesture that originates from the edge of the screen. Use the UIPanGestureRecognizer class for pan gestures and the UIScreenEdgePanGestureRecognizer class for screen-edge pan gestures.
The user must press one or more fingers on a view while panning on the screen. A panning gesture is on continuous action when the user moves one or more fingers allowed (minimumNumberOfTouches) to enough distance for recognition as a pan.
The iOS UITapGestureRecognizer class has a built-in way to detect a double tap on any view. All you need to do is create the recognizer, set its numberOfTapsRequired property to 2, then add it to the view you want to monitor.
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. It begins (UIGestureRecognizerStateBegan) when the minimum number of fingers allowed (minimumNumberOfTouches) has moved enough to be considered a pan. It changes (UIGestureRecognizerStateChanged) when a finger moves while at least the minimum number of fingers are pressed down. It ends (UIGestureRecognizerStateEnded) when all 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. } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With