Tap gesture without UITapGestureRecognizerPosted in iPhone Objective C development on August 05, 2010 by Pavel Sich 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.
- (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!
|
