0

我将 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%,但是在同一个视图上实现这两个手势的更好方法是什么,所以准确性更好?

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

4

2 回答 2

0

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

并添加此方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
于 2013-10-24T16:12:29.343 回答
0

我认为其他帖子有错字,但使用这个

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

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

requireGestureRecognizerToFail

于 2015-03-27T16:50:35.860 回答