Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view doesn't scroll when I use gesture recognizer

My app has a table view (with a scroll-into of course) and this view slides on and off with a gesture recognizer (like on the Facebook app).

If I use a button to slide [the table view onto the screen], it works fine but when I use a gesture recognizer, the table view can't be scrolled anymore.

Here is the code of gesture recognizer with the problem:

[self.view addGestureRecognizer:self.slidingViewController.panGesture];

Somebody have an idea?

like image 328
user2576304 Avatar asked Jul 12 '13 12:07

user2576304


3 Answers

Your gesture is probably preventing the scroll view gesture from working because by default only 1 gesture can be recognising at a time. Try adding yourself as the delegate of your gesture and implementing:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

self.slidingViewController.panGesture.delegate = self;

also, add <UIGestureRecognizerDelegate> to the list of protocols you implement

like image 200
Wain Avatar answered Nov 14 '22 13:11

Wain


I have used UIPangesture in my UItableview and to avoid this gesture I have used below delegate,

//This method helped me stopped up/down pangesture of UITableviewCell and allow only vertical scroll
override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
    if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
        let translation = panGestureRecognizer.translationInView(superview)
        if fabs(translation.x) > fabs(translation.y) {
            return true
        }
        return false
    }
    return false
}
like image 34
Pravin Kulkarni Avatar answered Nov 14 '22 13:11

Pravin Kulkarni


Here is the swift version:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}
like image 10
Swinny89 Avatar answered Nov 14 '22 11:11

Swinny89