rgb
rgb

Reputation: 33

swipe and pan gesture overlap

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.

Upvotes: 3

Views: 6344

Answers (2)

james00794
james00794

Reputation: 1147

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

}

Upvotes: 0

Eric
Eric

Reputation: 2097

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.

Upvotes: 11

Related Questions