Reputation: 49
I developed a 3d cube consist of 6 layer side by side to form a cube type structure. I am getting the single tap using touch event but the double tap is not working.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
NSLog(@"Single tap");
}
if ([touches count] == 2)
{
NSLog(@"Double tap"); // Not Working
}
}
How can i get the double tap working ?
Upvotes: 0
Views: 131
Reputation: 397
Besides being able to recognize a tap gesture in your app, you’ll probably want to distinguish a single tap, a double tap, or even a triple tap. Use a touch’s
tapCount
property to determine the number of times the user tapped a view.
Each touch returned in the NSSet is not exactly a tap. The OS recognize a double tap and returns it as one UITouch, so you can try to handle the event after the touch ended by using:
- (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];
}
}
}
If it still doesn't work and you are using UITapGestureRecognizer
take a look at the property numberOfTapsRequired
. If it is set to 1, try to change it to 2.
yourTapRecognizer.numberOfTapsRequired = 2;
The Apple Dev documentation may also help you understand how to use the UIGestureRecognizer
s correctly.
Upvotes: 2