很难捕获 UIButton 子类上的双击。 (捕获双击的时间延迟)
我正在谈论用同一根手指在屏幕上进行两次单独的触摸,
我认为我有正确的编码。但对我来说,在 iPad 上实际生成双击几乎是不可能的。是否可以增加单击和双击之间的时间间隔,以便更容易触发。我非常快速地双击,它会将其捕获为两次单击。只有有时我足够幸运才能触发双击。我将 UIButton 项目的子类放入滚动视图中。
无论如何,我的 UIButton 子类实现:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"Touch count:%d",touch.tapCount);
if (touch.tapCount == 1)
{
//Do things for one touch
}
else if (touch.tapCount == 2)
{
//Do things for double touch
}
}
这是捕获事件。这就是为什么我认为我的代码是正确的,我只是找不到与 UIEvent 有关的任何内容以及决定发生多少次触摸的内容。我在不同的 UIView 中测试了同样的东西,它的工作完全符合预期。
Im talking about two separate touches on the screen with the same finger
I think i have the coding right for this. but it is almost impossible for me to actually generate a double tap on my iPad. Is it possible to increase the time interval between a single and double tap, so it is easier to trigger. I do a double tap very fast and it captures it as two single clicks. only sometimes am i lucky enough to trigger a double tap. I place my subclass of UIButton item into a scrollview.
Anyway my subclass of UIButton implements:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"Touch count:%d",touch.tapCount);
if (touch.tapCount == 1)
{
//Do things for one touch
}
else if (touch.tapCount == 2)
{
//Do things for double touch
}
}
This is capturing the event. and that is why i think my code is right, i just couldnt find anything that has to do with UIEvent and what determines how many touches happen. I tested this same thing in a different UIView and it worked exactly as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码同时检测视图中的两个手指,而不是手指上的快速序列(双击)。
如果您想检测双击,最简单的方法是使用手势识别器。无论在哪里设置子类,都添加以下代码:
并实现一个方法来处理双击:
Your code is detecting two fingers in the view at the same time, not a rapid sequence of on finger (double tap).
If you want to detect a double tap, the easiest way is to use a Gesture Recoginizer. Wherever do setup of your sublass, add this code:
And implement a method to hande the double tap:
您没有调用
[super TouchsBegan:touches withEvent:event]
you not calling
[super touchesBegan:touches withEvent:event]