双击还是两个单击? [英] Double-tap or two single-taps?

查看:104
本文介绍了双击还是两个单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone OS上,两次点按两次点击的时间限制是多少?

What is the time limit for two taps to be considered a double-tap, on the iPhone OS?

//编辑:为什么这很重要?

// Why is this important?

为了处理单击和双击不同,Apple的指南说要执行 performSelector ... afterDelay 第一次点击时有一些合理的间隔(如果检测到第二次点击,则稍后取消)。

In order to handle single-tap and double-tap differently, Apple's guide says to do performSelector...afterDelay with some 'reasonable' interval on first tap (and cancel it later if the second tap is detected).

问题是如果间隔太短(0.1),即使在双击时也会执行单击操作(如果仅依赖于tapCount,则)。如果它太长(0.8),当没有可能进行双击时,用户将不必要地等待识别单击。

The problem is that if the interval is too short (0.1), the single tap action will be performed even when double-tapping (if relying only on tapCount, that is). If it's too long (0.8), the user will be waiting unnecessarily for the single-tap to be recognized, when there is no possibility for a double-tap.

它必须正好正确的数字,以便最佳地工作,但绝对不能更小,或者有机会出现错误(同时单击和双击)。

It has to be exactly the correct number, in order to work optimally, but definitely not smaller, or there's a chance for bugs (simultaneous single-tap and double-tap).

推荐答案

您可以通过点击手势检测任意数量的点按。无需使用 NSTouches 。对于在这里寻求解决方案的所有用户来说。

You can detect any number of tap by the tap gesture. No need of playing with NSTouches either. For all the user seeking for the solution here it is.

这些简单的代码行负责单点击和双击功能。

These simple lines of code does the duty of single and double tap functionality.

  UITapGestureRecognizer *doubleTapRecg = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self 
                                             action:@selector(doubleTapped:)];
    doubleTapRecg.delegate = self;
    doubleTapRecg.numberOfTapsRequired = 2;
    doubleTapRecg.numberOfTouchesRequired = 1;
    [view addGestureRecognizer:doubleTapRecg];


    UITapGestureRecognizer *tapRecg = [[UITapGestureRecognizer alloc]
                                       initWithTarget:self 
                                       action:@selector(tapped:)];
    tapRecg.delegate = self;
    tapRecg.numberOfTapsRequired = 1;
    tapRecg.numberOfTouchesRequired = 1;
    [view addGestureRecognizer:tapRecg];
    [tapRecg requireGestureRecognizerToFail:doubleTapRecg];


    [doubleTapRecg release];
    [tapRecg release];

这篇关于双击还是两个单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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