Khant Thu Linn Khant Thu Linn - 7 months ago 129
iOS Question

Objective-c shouldRecognizeSimultaneouslyWithGestureRecognizer disable otherGestureRecognizer

I have viewdeck controller and I can open left side-bar menu by swiping to the right.
For my center view controller, I also have uitableview.

Problem is that I can swipe to right to open menu and I also can scroll my tableview at the same time. I need to allow only one gesture at one time.

So, I check here

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

I found out like this. I need to disable UIPanGestureRecognizer or UIScrollViewPanGestureRecognizer to allow only 1 gesture at one time. May I know how to do?

//(lldb) po gestureRecognizer
//<UIPanGestureRecognizer: 0x79eef4d0; state = Possible; view = <UIView 0x79ee36e0>; target= <(action=panned:, target=<IIViewDeckController 0x79edb1d0>)>>

//(lldb) po otherGestureRecognizer
//<UIScrollViewPanGestureRecognizer: 0x79ff32f0; state = Began; delaysTouchesEnded = NO; view = <UITableView 0x7c301e00>; target= <(action=handlePan:, target=<UITableView 0x7c301e00>)>>


You could try setting the enabled property on the other gesture recogniser to NO. I don't have my dev environment up at the moment but I recall having done something similar before. Like so:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizershouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    otherGestureRecognizer.enabled = NO;
    return YES;