我有一个UIPanGestureRecognizer
的视图。该视图还包含UIScrollView
。
当用户平移ScrollView时,我在gestureRecognizerShouldBegin:
中返回NO,以确保ScrollView的手势识别器接管手势。
但是,我仍然收到gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
消息。它很容易修复,我只需要在gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
中返回NO,但我想知道在将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
答案 0 :(得分:1)
我认为这种行为还可以。
来自官方文档讨论的gestureRecognizerShouldBegin:
方法的以下参考:
当手势识别器尝试转换出
UIGestureRecognizerStatePossible
状态时,将调用此方法。返回NO会导致手势识别器转换到UIGestureRecognizerStateFailed
状态。
这清楚地表明它不会阻止手势识别器,但它会转换到相应手势识别器的UIGestureRecognizerStateFailed
状态。因此,其他委托方法将被正常调用。