滑动和平移手势重叠

时间:2013-08-28 14:47:37

标签: ios gestures

是否可以让特定手势失败,以便识别下一个可能的手势?

更具体一点,请查看示例代码段:

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

swipeLeft = UISwipeGestureRecognizerDirectionLeft;

swipeLeft.delegate = self;

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

pan.delegate = self;

[pan requireGestureRecognizerToFail:swipeLeft];

上面的代码指出,如果设备无法识别向左滑动,则会使用平移手势处理程序。

所以我的问题:是否可以根据在handleSwipe上检查的某些条件让swipeLeft故意失败(在被设备识别为向左滑动触摸后),让平移手势代替处理触摸输入?

感谢。

2 个答案:

答案 0 :(得分:11)

在此处查看UIGestureRecognizerDelegate协议:

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

具体来说,

gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

方法可能有用。如果您只是从此方法返回YES,则可以同时识别这两种手势,这样您就可以对这两种手势做出正确回应。

答案 1 :(得分:0)

假设您为平移手势实现了一些其他处理程序,那么您不能这样做:

-(void)handleSwipe:(id)sender {

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

-(void)handlePan:(id)sender {

    // handle pan gesture here

}