6

在我的应用程序中,我必须检测单次、两次和三次点击。所以,我正在使用 UITapGestureRecognizer。我正在使用以下代码:

    UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGestureOnAnimal:)];
    oneTap.numberOfTapsRequired = 1;

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGestureOnAnimal:)];
    doubleTap.numberOfTapsRequired = 2;
    [doubleTap requireGestureRecognizerToFail:oneTap];

    UITapGestureRecognizer* tripleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTripleTapGestureOnAnimal:)];
    tripleTap.numberOfTapsRequired = 3;
    [tripleTap requireGestureRecognizerToFail:doubleTap];

    [self addGestureRecognizer:oneTap];
    [self addGestureRecognizer:doubleTap];
    [self addGestureRecognizer:tripleTap];

但问题是它总是只检测单击和双击。它根本没有检测到三次点击....有人可以指出我在检测三次点击时所犯的错误吗?

4

2 回答 2

17

检查这个,

[oneTap requireGestureRecognizerToFail:doubleTap];
[oneTap requireGestureRecognizerToFail:tripleTap];
[doubleTap requireGestureRecognizerToFail:tripleTap];

你已经切换了方法中的水龙头,你没有做上面的第二行。理想情况下,只有在双击和三次敲击失败时才应检测到一次敲击。当三次点击失败时,应检测到双击。

于 2012-12-13T19:09:24.903 回答
0

将您的 2 个 requireGestureRecognizerToFail 调用更改为:

[oneTap requireGestureRecognizerToFail:tripleTap];
[oneTap requireGestureRecognizerToFail:doubleTap];
[doubleTap requireGestureRecognizerToFail:tripleTap];  
于 2012-12-13T19:11:05.843 回答