简体   繁体   English

滑动和平移手势重叠

[英]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? 所以我的问题:是否有可能让swipeLeft故意失败(在被设备识别为滑动左触摸之后)基于在handleSwipe上检查的一些标准,并让平移手势处理触摸输入?

thanks. 谢谢。

Check out the UIGestureRecognizerDelegate protocol here: 在这里查看UIGestureRecognizerDelegate协议:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html 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. 如果您只是从此方法返回YES ,则可以同时识别这两个手势,因此您可以对两者进行适当的响应。

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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