Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I chain two UIGestureRecognizers together?

What I would like to do is to detect a swipe gesture followed by a pan gesture as part of the same touch sequence. So the user first swipes an object to carry out an action, then, while keeping their finger on the screen, moves up/down to propagate the action to surrounding objects.

I have a swipe gesture recognizer and a pan gesture recognizer.

It seems to me that the ideal way to make them behave the way I want is to do this:

[myPanGestureRecognizer requireGestureRecognizerToSucceed:mySwipeGestureRecognizer];

But although I was sure that I hadn't just imagined requireGestureRecognizerToSucceed:, it seems I have.

Is there a way to achieve what I want without subclassing UIGestureRecognizer?

like image 267
oldbeamer Avatar asked Aug 12 '10 14:08

oldbeamer


People also ask

What is Pan gesture?

A pan gesture occurs any time a person 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.

What is UITapGestureRecognizer Swift?

UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer . For gesture recognition, the specified number of fingers must tap the view a specified number of times. Although taps are discrete gestures, they're discrete for each state of the gesture recognizer.


1 Answers

You can do this by setting both the swipe and the pan to recognize simultaneously, and subclassing the pan so that it does actually mark itself as recognized until the swipe has been recognized.

like image 153
Ben Stiglitz Avatar answered Oct 23 '22 16:10

Ben Stiglitz