iOS:取消使用2个手指时触摸UIScrollView

我编写了一个UIScrollView子类,用于滚动一系列UITableViews.请参见下图:

正如您所看到的,我有几个垂直滚动的UITableViews,它们在父UIScrollView中水平滚动.一切正常.然而,该应用程序有许多全局手势.例如,如果我用两根手指在给定方向上滑动,我会将UIView转换到应用程序的另一部分.但如果我在滚动视图和/或其子表视图之上执行手势,它们会自然地滚动其内容.这看起来不太好并导致一些布局问题.

我想弄清楚当用户用两根手指触摸任何地方,并且只用两根手指时,如何在UIScrollView及其子UITableViews上禁用所有滚动.我已经尝试过覆盖触摸的各种各样的触摸,触摸,触摸,触摸,取消等等……但我无法做到这一点.任何帮助深表感谢.

这是我的手势处理代码:

UISwipeGestureRecognizer *twoFingerSwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerSwipe:)];
[twoFingerSwipeUp setNumberOfTouchesRequired:2];
[twoFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[twoFingerSwipeUp setDelegate:self];

// 'self' is the superview of the UIScrollView, which is a UIView.
[self addGestureRecognizer:twoFingerSwipeUp];

[twoFingerSwipeUp release];

// ... repeat the above code for up, down, left, right gestures ...

- (void)handleTwoFingerSwipe:(UISwipeGestureRecognizer*)swipeGesture {

    switch ([swipeGesture direction]) {

        case UISwipeGestureRecognizerDirectionUp:            
            [self changeToView:viewAbove];
            break;

        case UISwipeGestureRecognizerDirectionDown:
            [self changeToView:viewBelow];            
            break;

        case UISwipeGestureRecognizerDirectionRight:
            [self changeToView:viewToTheRight];
            break;

        case UISwipeGestureRecognizerDirectionLeft:
            [self changeToView:viewToTheLeft];
            break;            
    }
}

最佳答案 尝试在所有滚动和表视图上设置panGestureRecognizer.maximumNumberOfTouches = 1(仅限iOS 5).

点赞