7

我将 singTap 和 doubleTap 添加到如下代码所示的视图中:

-(void)awakeFromNib{
    [self setUserInteractionEnabled:YES];
    //
    UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)];
    doubleTapGesture.numberOfTapsRequired = 2;
    [self addGestureRecognizer:doubleTapGesture];

    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
    singleTapGesture.numberOfTapsRequired = 1;
    [self addGestureRecognizer:singleTapGesture];
}

-(void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTapGesture{
    [[self delegate] singleTapOnView];
}

-(void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTapGesture{
    [[self delegate] doubleTapOnView];
}

当 doubleTap 时,singleTap 也会触发。doubleTap时如何禁用singleTap?谢谢!

4

1 回答 1

11

告诉单击识别器它需要双击识别器在触发之前失败:

[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];

(这实际上是UIGestureRecognizer 文档中此方法的规范示例。)

于 2013-03-22T01:51:24.700 回答