简体   繁体   中英

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.

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.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM