views:

16

answers:

1

How do I isolate touch events from each other? For example, I have one method that should be called if the view detects a single tap, and another method that should be called if the view detects a double-tap. The problem with the way I'm doing it is that a double-tap is always interpreted as a single tap before it is intereperted as a double tap. So, for example:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject]; if ([touch tapCount] == 1) { NSLog(@"one touch"); } else if ([touch tapCount] > 1) { NSLog(@"multi taps"); }

}

If I were to single tape the screen, I would correctly log "one touch". However, if I double tape the screen, I would get to logged statements, first "one touch" followed immediately by "multi taps".

I'm sure this is simple, but could someone point me in the right direction?

+1  A: 

Found the answer: http://www.iphonedevsdk.com/forum/iphone-sdk-development/3578-tap-double-tap.html

You use a switch and then cancel pending requests, ie:

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapMethod) object:nil];

isaac