I have a UIView
parentView
which implements a UITapGuestureRecognizer
and does something when tapped. parentView
has a sub view called childView
which also implements a UITapGuestureRecognizer
and does something when tapped.
There is an instance when I have to turn off the childViews
UITapGestureRecognizer
during an animation for a slight moment, and I noticed when it is turned off and I tap childView
, the tap gets intercepted by parentView
. Also, I have a toolbar attached to the top of this view that doesn't have any gesture recognizer attached to it, and it's touches get passed parentView (the buttons will barely work). I'm wondering is it possible to disable this without having a reference to the parents UITapGestureRecognizer?
I've tried using the exclusiveTouches
property of UIView
set to yes and it doesn't work. Any suggestions would be appreciated.
In the parent gesture recognizers, implement the UIGestureRecognizerDelegate
, and implement the following method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isKindOfClass:[ClassThatYouWantTouchesBlocked class]])
{
return NO;
}
else
{
return YES;
}
}
Replace ClassThatYouWantTouchesBlocked
with the class that you want its touches to be ignored.
What if never turn off the ChildView's tap gesture recognizer? if it is animating return from the child's tap gesture method without doing anything.
If it is an imageView than isAnimating property might come in use.
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