检测触摸次数

时间:2012-01-31 04:56:37

标签: iphone objective-c xcode ipad touches

伙计们,我想把行动设定为触动。如果人们单手触摸 - 一个动作,否则 - 不同。 我用touchesBegan方法编写了这段代码:

        UITouch *touch = [event.allTouches anyObject];
        BOOL tappedTwice = NO;
        if ([touch tapCount] == 2) {
            tappedTwice = YES;
            NSLog(@"double touch");
        }
        else if ([touch tapCount] == 1 && !tappedTwice) {
            NSLog(@"single touch");
        }

但它检测到单次触摸,并且在它加倍之后,但在我的情况下它是不正确的。你有什么想法吗?

1 个答案:

答案 0 :(得分:2)

检查link。只需通过设置

配置所需的点击次数
[tapGestureRecognizer   setNumberOfTapsRequired:2];

然后处理此方法

- (void)handleTap:(UITapGestureRecognizer *)sender {    
       if (sender.state == UIGestureRecognizerStateEnded)     {     
         // handling code     
       } 
}
相关问题