Ever needed to handle the tap event but needed to distinguish between tap and double tap? I guess everybody sometimes get to such issue and surprisingly prior iOS 4 there is no simple way how to do it.
With iOS4 you just call UITapGestureRecognizer and you are ready to go, so how to do it with version prior iOS4? Here you go:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSUInteger numTaps = [[touches anyObject] tapCount]; if (numTaps < 2) { [self performSelector:@selector(doSomeSingleTapAction) withObject:nil afterDelay: 0.25]; [self.nextResponder touchesEnded:touches withEvent:event]; } else { if(numTaps == 2) { [NSObject cancelPreviousPerformRequestsWithTarget:self]; [self performSelector:@selector(doSomeDblTapAction) withObject:nil afterDelay: 0.25]; } } }
Happy coding!