【问题标题】:SWRevealViewController panGestureRecognizer with UIScreenEdgeGestureRecognizerSWRevealViewController panGestureRecognizer 与 UIScreenEdgeGestureRecognizer
【发布时间】:2015-10-28 07:00:51
【问题描述】:

我一直在寻找这个问题的解决方案,但没有找到任何解决方案。所以我在我的项目中使用 SWRevealViewController 作为侧边栏菜单,但我希望当用户从视图的左边缘触摸时,侧边菜单会打开。我想要这个,因为我有另一个用于左右滑动的 swipeGestureRecognizer。要添加左右滑动,我使用以下代码:

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedToRight:)];
        swipeRight.direction = UISwipeGestureRecognizerDirectionRight;

   UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(swipedToLeft:)];
       swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;

所以我的问题是如何让侧边菜单仅在从左边缘开始触摸时打开?

UPD 1

我使用此代码通过在屏幕的任何部分平移来打开侧边菜单

[self.view addGestureRecognizer: self.revealViewController.panGestureRecognizer];

我有识别器向右滑动。问题是一旦打开菜单并执行滑动操作。我想只允许从左边缘触摸时打开菜单

UPD 2 已解决

我通过设置可拖动边框宽度解决了这个问题:

self.revealViewController.draggableBorderWidth = self.view.frame.size.width / 2;

现在从边缘到中心的手势打开菜单,从中心到右边框执行滑动操作

【问题讨论】:

    标签: ios objective-c swrevealviewcontroller


    【解决方案1】:

    您可以像之前提到的那样添加 UIPanGestureRecognizer 或在视图顶部添加子视图并为其添加手势:

    UIView *topView = ...
    [self.view addSubview: topView];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
                                       initWithTarget:self action:@selector(didPan:)];
    
    [topView addGestureRecognizer:pan];
    

    【讨论】:

      【解决方案2】:

      我要做的是修改 UINavigationController 类中已经存在的弹出手势。

      添加到您的 viewWillAppear 的示例代码:

      if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
          self.navigationController.interactivePopGestureRecognizer.enabled = NO;
          // Your code here
      }
      

      【讨论】:

        【解决方案3】:

        我要做的是修改 UINavigationController 类中已经存在的弹出手势。

        【讨论】:

          猜你喜欢
          • 2016-01-27
          • 2014-06-30
          • 2016-03-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-19
          • 1970-01-01
          相关资源
          最近更新 更多