Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIGestureRecognizer blocking table view scrolling

I'm using a custom UIGestureRecognizer subclass to track gestures on my InfoView class. The InfoView class is a subview of a custom UITableViewCell subclass called InfoCell.

I've added my gesture recognizer to my root view (the parent view of everything else on screen, because the purpose of my custom gesture recognizer is to allow dragging of InfoCell views between tables). Now, everything works as it should except one thing. I'm using the following code in my UIGestureRecognizer subclass to detect touches on the InfoView view:

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

The problem here is that the touches on the InfoView object are being intercepted, therefore they are not being forwarded to the UITableView which contains the InfoCell, which is the parent view of the InfoView. This means that I can no longer scroll the table view by dragging on the InfoView view, which is an issue because the InfoView covers the entire InfoCell.

Is there any way I can forward the touches onto the table view so that it can scroll? I've tried a bunch of things already:

[super touchesBegan:touches withEvent:event];

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

But nothing has worked so far. Also, the cancelsTouchesInView propery of my UIGestureRecognizer is set to NO, so thats not interfering with the touches.

Help is appreciated. Thanks!

like image 588
indragie Avatar asked Jul 20 '10 23:07

indragie


1 Answers

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

If this returns YES it will prevent your gesture recognizer from stomping on the one that UIScrollView is using to detect scrolling.

like image 184
Mark Adams Avatar answered Dec 25 '22 17:12

Mark Adams