3

我想抓住UIGestureRecognizer. 我可以这样做吗?

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    NSLog(@"Gesture should begin");
    if ([gestureRecognizer isMemberOfClass:[UIRotationGestureRecognizer class]])
        NSLog(@"rotate");
    if ([gestureRecognizer isMemberOfClass:[UIPinchGestureRecognizer class]])
        NSLog(@"pinch");
    if ([gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]])
        NSLog(@"tap");
    if ([gestureRecognizer isMemberOfClass:[UIPanGestureRecognizer class]])
        NSLog(@"pan");
    if ([gestureRecognizer isMemberOfClass:[UILongPressGestureRecognizer class]])
        NSLog(@"long");
    if ([gestureRecognizer isMemberOfClass:[UISwipeGestureRecognizer class]])
        NSLog(@"swipe");
    return NO;
}

我在表格视图单元格中有一个长触摸手势。如果我按下单元格,我会收到一条日志:

-[FileObjectView gestureRecognizerShouldBegin:] [Line 45] Gesture should begin
-[FileObjectView gestureRecognizerShouldBegin:] [Line 55] long

我希望它以这种方式工作。

但有时当我滚动表格视图时,我会收到一条日志:

-[FileObjectView gestureRecognizerShouldBegin:] [Line 45] Gesture should begin

这让我觉得我不知道某种手势。

有人能解释一下情况吗?

4

1 回答 1

1

我决定以这种方式检查类名:

NSLog(@"%@",gestureRecognizer.class);

班级名称是:UIScrollViewPanGestureRecognizer

我已经在不同的 iOS 版本上多次检查过这个问题。

这件事只发生在 iOS 6 上。还有一个 iOS 6 错误?!

于 2012-10-24T10:18:16.253 回答