質問

guys, I want to set actions to touches. If people make single touch - one action, else - different. I've written this code in my touchesBegan method:

        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");
        }

But it's detecting single touch, and after it double, but it's incorrect in my situation. Have you any ideas?

役に立ちましたか?

解決

Check this link. Just Configure number of tap required by setting

[tapGestureRecognizer   setNumberOfTapsRequired:2];

and then handle this method

- (void)handleTap:(UITapGestureRecognizer *)sender {    
       if (sender.state == UIGestureRecognizerStateEnded)     {     
         // handling code     
       } 
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top