Scrolling UIGestureRecognizer lock table table

I am using a custom subclass of UIGestureRecognizer to track gestures in my InfoView class. The InfoView class is a subheading of a custom subclass of UITableViewCell called InfoCell .

I added my gesture recognizer to my root mode (the parent view of everything else on the screen, because the goal of my custom gesture recognizer is to let InfoCell drag and drop views between tables). Now everything works as it should, except for one. I use the following code in a subclass of UIGestureRecognizer to detect touches in an InfoView :

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UIView *touchView = [[touches anyObject] view]; if ([touchView isKindOfClass:[InfoView class]]) { // Do stuff } 

The problem is that the touches of the InfoView object are intercepted, so they are not forwarded to the UITableView , which contains InfoCell , which is the parent view of InfoView . This means that I can no longer scroll the table view by dragging and dropping the InfoView view, which is a problem because the InfoView spans the entire InfoCell .

Is there any way to move the touches to the table view so that it can scroll? I already tried a bunch of things:

[super touchesBegan:touches withEvent:event];

[touchView.superview.superview touchesBegan:touches withEvent:event]; ( touchView.superview.superview gets a link to its parent UITableView )

But so far nothing has happened. In addition, the cancelsTouchesInView property of my UIGestureRecognizer set to NO , so it does not interfere with touches.

Help is appreciated. Thanks!

+7
cocoa-touch ipad uiview uigesturerecognizer
source share
4 answers

I had a line in my touchesBegan method that sets the state property of the gesture recognizer to UIGestureRecognizerStateBegan . Removing this line seems to fix the problem.

+3
source share

Check the UIGestureRecognizerDelegate method: - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

If this returns YES, it will not allow your gesture recognizer to stomp on what UIScrollView uses to detect scrolling.

+24
source share

UIGestureRecognizer has the "cancelsTouchesInView" property, which is set to YES by default. This means that touching the UIView is canceled when the gesture is recognized. Try setting NO so that UIScrollView can receive additional touch events.

+9
source share

You can try adding this notification.

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if ([gestureRecognizer class] == [UIPanGestureRecognizer class]) { UIPanGestureRecognizer *panGestureRec = (UIPanGestureRecognizer *)gestureRecognizer; CGPoint point = [panGestureRec velocityInView:self]; if (fabsf(point.x) > fabsf(point.y) ) { return YES; } } return NO; } 
+3
source share

All Articles