Question

I'm addding a UIPanGestureRecognizer to one custom view in my view controller.

I'm also using MFSideMenu for sliding menu which in its framework adds a UIPanGestureRecognizer to the main NavigationViewController.view.

Sometimes when the I'm panning inside my custom view the pan is actually occurring in the MavigationViewController.view.

What causes this problem is the following code in the MFSideMenu implementation of:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

  if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {

     if([gestureRecognizer.view isEqual:self.rootViewController.view] &&
       [self rootViewControllerPanEnabled])
      {
        return YES;
      }

   return NO;
  }

}

Apperantely sometimes (1 out of 5-10), this method returns YES, where it should return NO when panning on the view itself!

The problem being that instead of panning the custom view, the sliding menu gets opened.

I've pretty much tried everything I could imagine - this behavior simply doesn't make any sense.

UPDATE: Problem only in iOS 7 - please see below my answer for the fix.

Was it helpful?

Solution

Found the solution; Apparently the problem is in iOS 7.

To fix it, simply implement UIGestureRecognizerDelegate in your view controller and implement:

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

This has fixed my random problem!

Credits to UIPanGestureRecognizer sometimes not working on iOS 7

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top