【发布时间】:2016-01-27 20:41:15
【问题描述】:
-
如果我在 frontViewController(在我的情况下是 HomescreenViewController)中已经有一些其他滑动手势,我如何使用 panGestureRecognizer 打开 sideMenu? 我的 frontViewController 包含一个有 5 个页面的 pageViewController。因此 pageViewController 已经启用了向左滑动和向右滑动。
我在frontViewController的viewDidLoad中使用了如下代码:
_sideButton.target = self.revealViewController; _sideButton.action = @selector(revealToggle:); [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; [self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];这不会与 pageViewController 向右滑动一起完成。 然后我使用这段代码:
self.revealViewController.draggableBorderWidth = self.view.frame.size.width / 2;但这也不起作用。我使用的是最新的 SWRevealViewController 2.4.0 版
这是我的 frontViewController 的视图层次结构。 HomescreenViewController>pagerView>PageviewController>listingViewController
另外,当侧边菜单出现时,frontviewController 的部分处于活动状态,当我尝试通过向左滑动来关闭侧边菜单时,它会将其识别为 pageviewcontroller 滑动。我希望第一个问题的解决方案也能解决这个问题。
更新(答案):
查找问题 2 的已接受答案。
对于第一个问题,如果您遇到像我这样的问题,只需使用下面的代码创建一个左侧宽度为 20 像素的视图,并将 panGestureRecognizer 添加到此视图中(在viewWillAppear)。
SWSwipeViewForPanGesture=[[UIView alloc]initWithFrame:CGRectMake(0, 0,20, self.view.frame.size.height)];
_SWSwipeViewForPanGesture.backgroundColor=[UIColor clearColor];
[self.view addSubview:_SWSwipeViewForPanGesture];
[_SWSwipeViewForPanGesture addGestureRecognizer:self.revealViewController.panGestureRecognizer];
另外,我必须在- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position方法中添加以下代码这是一个委托方法。所以,你应该在viewdidload中确认委托。
[_SWSwipeViewForPanGesture addGestureRecognizer:self.revealViewController.panGestureRecognizer];
[self.view bringSubviewToFront:_SWSwipeViewForPanGesture];
就是这样。它很简单!
【问题讨论】:
标签: ios objective-c uipageviewcontroller uipangesturerecognizer swrevealviewcontroller