简体   繁体   English

UIPanGestureRecognizer冲突

[英]UIPanGestureRecognizer conflicts

I'm addding a UIPanGestureRecognizer to one custom view in my view controller. 我正在将UIPanGestureRecognizer添加到我的视图控制器中的一个自定义视图。

I'm also using MFSideMenu for sliding menu which in its framework adds a UIPanGestureRecognizer to the main NavigationViewController.view. 我还将MFSideMenu用于滑动菜单,该菜单在其框架中向主NavigationViewController.view添加了UIPanGestureRecognizer。

Sometimes when the I'm panning inside my custom view the pan is actually occurring in the MavigationViewController.view. 有时,当我在自定义视图中平移时,平移实际上发生在MavigationViewController.view中。

What causes this problem is the following code in the MFSideMenu implementation of: 导致此问题的原因是MFSideMenu实现中的以下代码:

- (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! 有时(在5-10中,有1个)是适当的,此方法返回YES,在平移视图本身时应返回NO!

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. 更新:仅在iOS 7中存在问题-请在下面的答案中查看该修复程序。

Found the solution; 找到了解决方案; Apparently the problem is in iOS 7. 显然问题出在iOS 7中。

To fix it, simply implement UIGestureRecognizerDelegate in your view controller and implement: 要修复它,只需在视图控制器中实现UIGestureRecognizerDelegate并实现:

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

This has fixed my random problem! 这解决了我的随机问题!

Credits to UIPanGestureRecognizer sometimes not working on iOS 7 贷记到UIPanGestureRecognizer有时在iOS 7上不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM