Enable vertical scroll: UITableView and Pan gesture

I had a view inside the UITableViewCell, this view had a pan gesture. I was doing some tranform update on horizontal panning. Somehow vertical scroll of UITableView just stopped working since pan gesture on my view was taking up the preference.

Here is the not so complex solution but hard to understand/find, this really was an oasis on a middle of desert. Override gestureRecognizerShouldBegin, return YES only if direction of pan is horizontal

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
{
    UIView *gestureView = [gestureRecognizer view];
    CGPoint translation = [gestureRecognizer translationInView:[gestureView superview]];
    
    // Check for horizontal gesture
    if (fabsf(translation.x) > fabsf(translation.y))
    {
        return YES;
    }
    
    return NO;
}

One Comment

  • Merci, exactement ce que je voulais !

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>