SWRevealViewController panGestureRecognizer 和 UIScreenEdgeGestureRecognizer
SWRevealViewController panGestureRecognizer with UIScreenEdgeGestureRecognizer
我一直在寻找这个问题的解决方案,但没有找到。所以我在我的项目中使用 SWRevealViewController 作为侧边栏菜单,但我希望当用户开始从视图的左边缘触摸时,侧边菜单会打开。我想要这个,因为我有另一个左右滑动手势识别器 swipe.For 添加左右滑动我使用这个代码:
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;
现在从边缘到中心的手势打开菜单,从中心到右边框执行滑动的动作
您可以像之前提到的那样添加一个 UIPanGestureRecognizer,或者在您的视图顶部添加一个子视图并向其添加一个手势:
UIView *topView = ...
[self.view addSubview: topView];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(didPan:)];
[topView addGestureRecognizer:pan];
我要做的是修改 UINavigationController
class.
中内置的已经存在的弹出手势
添加到 viewWillAppear 的示例代码:
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
// Your code here
}
我要做的是修改 UINavigationController 中内置的已经存在的弹出手势 class。
我一直在寻找这个问题的解决方案,但没有找到。所以我在我的项目中使用 SWRevealViewController 作为侧边栏菜单,但我希望当用户开始从视图的左边缘触摸时,侧边菜单会打开。我想要这个,因为我有另一个左右滑动手势识别器 swipe.For 添加左右滑动我使用这个代码:
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;
现在从边缘到中心的手势打开菜单,从中心到右边框执行滑动的动作
您可以像之前提到的那样添加一个 UIPanGestureRecognizer,或者在您的视图顶部添加一个子视图并向其添加一个手势:
UIView *topView = ...
[self.view addSubview: topView];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(didPan:)];
[topView addGestureRecognizer:pan];
我要做的是修改 UINavigationController
class.
添加到 viewWillAppear 的示例代码:
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
// Your code here
}
我要做的是修改 UINavigationController 中内置的已经存在的弹出手势 class。