草庐IT

ios - SWRevealViewController panGestureRecognizer 和 UIScreenEdgeGestureRecognizer

coder 2024-01-16 原文

我一直在寻找这个问题的解决方案,但没有找到。所以我在我的项目中使用 SWRevealViewController 作为侧边栏菜单,但我希望当用户开始从 View 的左边缘触摸时,侧边菜单会打开。我想要这个,因为我有另一个用于左右滑动的 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;

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

最佳答案

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

关于ios - SWRevealViewController panGestureRecognizer 和 UIScreenEdgeGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31833577/

有关ios - SWRevealViewController panGestureRecognizer 和 UIScreenEdgeGestureRecognizer的更多相关文章

随机推荐