Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIGestureRecognizer blocking tableview scrolling

I have a table with static cells. One of these cells has a view in it with a pan gesture recogniser on it.

When I am scrolling down my tableview, when I get to the cell with the view with pan gesture recogniser, scrolling doesn't seem to work. If I touch outside the view (to the side or top or bottom) it works and I can scroll. I have an if statement in my gesturerecognizer that tests whether a certain area has been touched, and if so performs an action.

I have looked at this issue (http://stackoverflow.com/questions/3295239/uigesturerecognizer-blocking-table-view-scrolling) but setting cancelsTouchesInView to NO didn't work, I don't have anywhere setting the state property and using the method - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer I don't know where to get the 'otherGestureRecognizer' from or what object to call that method on.

I'm assuming I wan't to put my gesture recogniser as the first argument, and the tableview's scroll gesture recogniser as the otherGestureRecogniser, is that correct? If so, how do I get that?

UIPanGestureRecognizer *windPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveWindHandle:)];

[self.windRangeView addGestureRecognizer:windPanGesture];

Then in my moveWindHandle:

 -(void)moveWindHandle:(UIPanGestureRecognizer *)gesture
{
    gesture.cancelsTouchesInView = NO;
    isMovingHandle = [self isPoint:startedTouchAt insideHandle:_toHandleWindImageView];
    if(isMovingHandle) {

        if(gesture.state == UIGestureRecognizerStateBegan) {
            //do stuff
        }
    } 
    else
    {
        //i want it to ignore this gesture and just scroll like normal if that is what hte user did
    }
}

I have set the tableviewcontroller as a UIGestureRecognizerDelegate, but I don't know what to do with that.

like image 246
Brentoe Avatar asked Feb 19 '23 22:02

Brentoe


1 Answers

You would not be the one calling -gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:. That method is called by the system. You need to set your table view controller as the delegate for your window pan gesture.

windPanGesture.delegate = self;

At that point, when you do the pan, the system will call the delegate method -gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: with your gesture recognizer as one argument and the scroll view's gesture recognizer as the other.


Update

You may also want to implement the -gestureRecognizerShouldBegin: method and return NO if you are not in one of the certain areas.

like image 98
Jeffery Thomas Avatar answered Mar 07 '23 11:03

Jeffery Thomas