2

我有一个视图,它有一个UIPanGestureRecognizer. 同一个视图还包含一个UIScrollView.

当用户平移 ScrollView 时,我返回 NO in gestureRecognizerShouldBegin:,以确保 ScrollView 的手势识别器接管手势。

但是,我仍然收到gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:消息。很容易解决,我只需要在中返回NO gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:,但是我想知道在返回NO后收到这个消息是否正常gestureRecognizerShouldBegin:

代码

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"gestureRecognizerShouldBegin:0x%x - return NO", (int)gestureRecognizer);
    return NO;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    NSLog(@"gestureRecognizer:0x%x shouldRecognizeSimultaneouslyWithGestureRecognizer:0x%x", (int)gestureRecognizer, (int)otherGestureRecognizer);
    return YES;
}

输出

2013-03-04 11:30:14.876 XXXX[99271:19d03] gestureRecognizerShouldBegin:0x9d6c380 - return NO
2013-03-04 11:30:14.876 XXXX[99271:19d03] gestureRecognizer:0x9d6c380 shouldRecognizeSimultaneouslyWithGestureRecognizer:0xbb75240
4

1 回答 1

1

我认为这种行为是可以的。gestureRecognizerShouldBegin:来自官方文档讨论的以下方法参考:

当手势识别器尝试转换出UIGestureRecognizerStatePossible状态时调用此方法。返回 NO 会导致手势识别器转换到UIGestureRecognizerStateFailed状态。

这清楚地表明它不会阻止手势识别器,但会转换到UIGestureRecognizerStateFailed相应手势识别器的状态。所以其他委托方法将被正常调用。

于 2014-08-14T09:39:01.117 回答