UITapGestureRecognizer in UIView and its preview will respond together when Subview is clogged

UITapGestureRecognizer applies to both UIImageView and its subzone ( UITextView ). However, when I click on subview, the receiver becomes a subview and its parent view (i.e. UIImageView + UITextView ). However, it should only be a subview , because this is the one I used. I assumed that nested gestures would react first, but apparently the parent receives a fist, and then goes to the child.

Thus, there are various solutions for different scenarios (not similar to mine, but rather the buttons inside the scroll conflict). How can I easily fix my problem without a possible subclass and to support iOS 6+? I tried postponing the start of the UIGestureRecognizer on UIImageView , and I tried setting cancelsTouchesInView to NO - all without luck.

+4
ios objective-c iphone uiview uigesturerecognizer
source share
3 answers

Try using the following code:

match UIGestureRecognizerDelegate > to your class.

set yourGesture.delegate = self ;

then add this delegate. Method:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { // return YES (the default) to allow the gesture recognizer to examine the touch object, NO to prevent the gesture recognizer from seeing this touch object. if([touch.view isKindOfClass: [UITextView class]] == YES)] { return YES; } else { return NO; } } 

Hope it solves your problem. Enjoy the coding .. !!!!

+9
source share

What he should do. The hierarchical hierarchy looks like a tree structure, and its traversal during touch gestures begins with the root node. It is very likely that your parental look will first receive a gesture, and then its subitems. Bypass skips nodes for which

userInteractionEnabled = NO.

since you don’t have a code, I cannot help you play with this flag. A more general solution is to always set the gesture only for your parent element, and gesture delegates check the coordinates if they belong to one of the subzones, and if so, call your gesture method for your spying. Not a clean approach, but it works. !!

+3
source share

you should implement the UIGestureRecognizer delegation methods and apply the correct policy to the gesture if multiple gestures are recognized

0
source share

All Articles