I add singTap and doubleTap to a view like the code below:
-(void)awakeFromNib{
[self setUserInteractionEnabled:YES];
//
UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)];
doubleTapGesture.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTapGesture];
UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
singleTapGesture.numberOfTapsRequired = 1;
[self addGestureRecognizer:singleTapGesture];
}
-(void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTapGesture{
[[self delegate] singleTapOnView];
}
-(void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTapGesture{
[[self delegate] doubleTapOnView];
}
When doubleTap the singleTap also fire. How to disable singleTap when doubleTap? Thanks!
Tell the single-tap recognizer that it requires the double-tap recognizer to fail before it triggers:
[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];
(This is actually the canonical example in the UIGestureRecognizer docs for this method.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With