iphone - 双击故障安全方式 [英] iphone - double tap fail safe way
问题描述
我正在尝试检测视图上的双击,但是当双击时,第一次点按会触发TouchesBegan上的操作,因此,在检测到双击之前,始终会首先检测到单击。
I am trying to detect double taps on a view, but when the double tap comes, the first tap triggers an action on TouchesBegan, so, before detecting a double tap a single tap is always detected first.
如何才能检测到双击?
我不能使用OS 3.x手势,因为我必须使它与旧操作系统版本兼容。
I cannot use OS 3.x gestures, because I have to make it compatible with old OS versions.
谢谢
推荐答案
scrollViewSuite示例代码的tapZoom示例中的一些摘录:
Some excerpts from the tapZoom example of the scrollViewSuite sample code:
首先,触摸结束后启动的功能:
First, the function to kick off things once the touch ended:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 1) {
[self performSelector: @selector(handleSingleTap)
withObject: nil
afterDelay: 0.35]; // after 0.35s we call it a single tap
} else if([touch tapCount] == 2) {
[self handleDoubleTap];
}
}
第二:拦截消息超时期间发生新触摸:
Second: intercept the message if a new touch occurs during timeout:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[NSObject cancelPreviousPerformRequestsWithTarget: self
selector: @selector(handleSingleTap)
object: nil];
}
在这里:( scrollView套件)
http:// developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Introduction/Intro.html
and here: (scrollView suite) http://developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Introduction/Intro.html
这篇关于iphone - 双击故障安全方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!