冲突的UIPanGestureRecognizer(3指)和UIPinchGestureRecognizer

时间:2013-10-24 15:56:53

标签: ios objective-c uigesturerecognizer uipangesturerecognizer uipinchgesturerecognizer

我将UIPanGestureRecognizer和UIPinchGestureRecognizer添加到同一视图中。这通常不会导致任何问题,但使用我的UIPanGestureRecognizer对3个手指的要求会导致问题:

UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinched:)];
[self.view addGestureRecognizer:pinchGesture];

UIPanGestureRecognizer panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panning:)];
panGesture.minimumNumberOfTouches = 3;
panGesture.maximumNumberOfTouches = 3;
[self.view addGestureRecognizer:panGesture];

有时候,应该在平底锅时调用捏手势。它可以在50%的时间内工作,但是在同一视图上实现这两个手势的更好方法是什么,所以准确性更好?

编辑:我只希望一次发生一个手势。

2 个答案:

答案 0 :(得分:0)

将手势的代表设置为self并设置ViewController以实现UIGestureRecognizerDelegate

并添加此方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

答案 1 :(得分:0)

其他帖子我认为有错字,但请使用此

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return NO;
}

并添加此项,以便其他手势在您要开始的手势之前失败

requireGestureRecognizerToFail