iOS - 多个Tap手势识别器 [英] iOS - Multiple Tap gesture recognizers

查看:266
本文介绍了iOS - 多个Tap手势识别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我要检测单,双和三个水龙头。所以,我正在使用UITapGestureRecognizer。我正在使用以下代码:

In my application, i've to detect single, double and triple taps. So, I'm using UITapGestureRecognizer. I'm using the following code:

    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];

但问题是它始终仅检测单击和双击。它根本没有检测到三重敲击......有人可以指出我在检测三重敲击时所犯的错误吗?

But the problem is that its always detect single and double taps only. Its not detecting triple tap at all.... can some one point out the mistake that I am doing to detect triple taps?

推荐答案

用此检查,

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

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

You had switched the taps in the methods and you were not doing the second line above. Ideally one tap should be detected only when double tap and triple tap fails. And double tap should be detected when triple tap fails.

这篇关于iOS - 多个Tap手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆