如何在瞬间识别oneTap/doubleTap? [英] How to recognize oneTap/doubleTap at moment?
问题描述
我知道使用Apple API过滤oneTap/doubleTap.代码如下.
I Know filtering oneTap/doubleTap using a Apple API. code are follows.
UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTapGestureRecognizer.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTapGestureRecognizer];
UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
**[singleTapGestureRecognizer requireGestureRecognizerToFail: doubleTapGestureRecognizer];**
[self addGestureRecognizer:singleTapGestureRecognizer];
但是oneTap/doubleTap checkDelayTime感觉太长了(大约0.5秒?). 通常App用户的反应非常快.尽管0.5秒通常是短时间.但是在移动设备环境中使用时间很长,因为用户的反应非常重要.
but oneTap/doubleTap checkDelayTime is feeling a so Long (About 0.5sec?). Generally App Users of the reaction is very fast. Although 0.5 seconds is typically short-time. but In Mobile Device Environment is long-time, because users react is very important.
说到这一点,YouTubeApp 具有一个非常完美的算法,可以立即过滤/双击. oneTap-doubleTap checkDelay是VeryVeryShort完美优化.
Speaking to the point, YouTubeApp have a very Perfectly algorithm about filtering at a moment oneTap/doubleTap. oneTap-doubleTap checkDelay is VeryVeryShort Perfectly Optimization.
oneTap(显示/隐藏控制栏)
oneTap(show/hidden controlBar)
doubleTap(完整/默认videoScreenSize)
doubleTap(full/default videoScreenSize)
如何像YoutubeApp一样实现?关于oneTap-doubleTap过滤不使用requireGestureRecognizerToFail选择器.关于很短的延迟oneTap-doubleTap区分.
How to implement like YoutubeApp? about oneTap-doubleTap filtering Not Using a requireGestureRecognizerToFail Selector. about very short delay oneTap-doubleTap distinguishing.
我认为YoutubeApp没有使用requireGestureRecognizer选择器.
I think YoutubeApp is Not Use a requireGestureRecognizer Selector.
推荐答案
如果没有手势识别器,这最容易做到.然后,您可以控制延迟.下面的代码是我在一个项目中使用的Apple原始文档的变体.我有博客帖子也对此进行了讨论.
This is easiest to do without gesture recognizers. Then you can control the delay. The code below is a variation of Apple's original documentation that I use in one of my projects. I have blog post that talks about it as well.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if (touch.tapCount == 2) {
//This will cancel the singleTap action
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if (touch.tapCount == 1) {
//if they tapped within the coin then place the single tap action to fire after a delay of 0.3
if (CGRectContainsPoint(coin.frame,[touch locationInView:self.view])){
//this is the single tap action being set on a delay
[self performSelector:@selector(onFlip) withObject:nil afterDelay:0.3];
}else{
//I change the background image here
}
} else if (touch.tapCount == 2) {
//this is the double tap action
[theCoin changeCoin:coin];
}
}
这篇关于如何在瞬间识别oneTap/doubleTap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!