在UIScrollView上检测2触控平移与1触摸平移?

时间:2015-10-30 20:10:54

标签: ios objective-c iphone uiscrollview

我有一个内部有UIImageView的UIScrollView。我将UIScrollView设置为仅使用2个手指平移手势滚动,这样可以正常工作。以下是我使用的代码:

for (UIGestureRecognizer *gestureRecognizer in _imgScrollView.gestureRecognizers) {
        if ([gestureRecognizer  isKindOfClass:[UIPanGestureRecognizer class]]) {
            UIPanGestureRecognizer *panGR = (UIPanGestureRecognizer *) gestureRecognizer;
            panGR.minimumNumberOfTouches = 2;
            panGR.maximumNumberOfTouches = 2;
        }
    }

我想用触摸事件(touchesBegan:,touchesMoved:,touchesEnded :)捕获1个手指平移,并将这些事件传递给UIScrollView下的另一个UIView。

我想这样做的原因是因为另一个UIView是一个绘图视图,用户可以在其中绘制线条。此绘图视图不使用平移手势识别器来绘制线条,只需简单的touchesBegan,touchesMoved和touchesEnded方法。用户应该能够用2个手指滚动图像并用1个手指绘制,这是最终目标功能。

我意识到其他问题已经问了类似的问题,但是我还没有能够找到一个关于如何分别处理2个手指平底锅和1个手指平底锅的结论性答案。这是我的viewDidLoad方法,我实现了scrollView:

-(void)viewDidLoad
{
    [super viewDidLoad];

    _imgScrollView.delegate = self;
    imgView = [[UIImageView alloc] init];
    [_imgScrollView addSubview:imgView];
    _imgScrollView.showsVerticalScrollIndicator = NO;
    _imgScrollView.showsHorizontalScrollIndicator = NO;
    for (UIGestureRecognizer *gestureRecognizer in _imgScrollView.gestureRecognizers) {
        if ([gestureRecognizer  isKindOfClass:[UIPanGestureRecognizer class]]) {
            UIPanGestureRecognizer *panGR = (UIPanGestureRecognizer *) gestureRecognizer;
            panGR.minimumNumberOfTouches = 2;
            panGR.maximumNumberOfTouches = 2;
        }
    }
}

提前致谢。

0 个答案:

没有答案