Question

is it possible to let a specific gesture fail so the next possible gesture is recognized?

to be more specific, look at the sample snippet:

UISwipeGestureRecognizer *swipeLeft = [initialize UISwipeGestureRecognizer... @selector(handleSwipe:)]

swipeLeft = UISwipeGestureRecognizerDirectionLeft;

swipeLeft.delegate = self;

UIPanGestureRecognizer *pan = [initialize UIPanGestureRecognizer... @selector(handlePan:)]

pan.delegate = self;

[pan requireGestureRecognizerToFail:swipeLeft];

the above code states that if swipe left is not recognized by the device, pan gesture handler will be used.

so my question: is it possible to let swipeLeft intentionally fail (after being recognized as swipe left touch by the device) based on some criteria that is checked on handleSwipe, and let the pan gesture handle the touch input instead?

thanks.

Was it helpful?

Solution

Check out the UIGestureRecognizerDelegate protocol here:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html

Specifically, the

gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

method might be useful. If you simply return YES from this method, both gestures can be recognized at the same time, so you can respond properly to both.

OTHER TIPS

Assuming you have some other handler implemented for the pan gesture, can't you just do:

-(void)handleSwipe:(id)sender {

    if //criteria is met to ignore left swipe
    {
        [self handlePan:self];   
    }
}

-(void)handlePan:(id)sender {

    // handle pan gesture here

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top