我开发了一个由6层并排组成的三维立方体,以形成一个立方体类型的结构。我得到的单一点击使用触摸事件,但双龙头不工作。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
NSLog(@"Single tap");
}
if ([touches count] == 2)
{
NSLog(@"Double tap"); // Not Working
}
}我怎么才能让双龙头工作呢?
发布于 2014-10-09 12:15:47
除了能够识别你的应用程序中的一个点击手势,你可能想要区分一个单一的点击,一个双点击,甚至一个三拍。使用touch的
tapCount属性确定用户点击视图的次数。
在NSSet中返回的每一个触摸都不完全是一个点击。操作系统识别双击并将其返回为一个UITouch,因此您可以尝试在触摸结束后通过以下方法处理事件:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *aTouch in touches) {
if (aTouch.tapCount >= 2) {
// The view responds to the tap
[self respondToDoubleTapGesture:aTouch];
}
}
}如果它仍然不工作,并且您正在使用UITapGestureRecognizer,请查看属性numberOfTapsRequired。如果设置为1,则尝试将其更改为2。
yourTapRecognizer.numberOfTapsRequired = 2;Apple Dev文档还可以帮助您理解如何正确使用UIGestureRecognizer。
https://stackoverflow.com/questions/26276182
复制相似问题