带有pageViewController iOS的SWRevealViewController panGestureRecognizer(滑动时的侧边菜单)

  1. 如果我在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

  2. 此外,当出现侧面菜单时,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添加以下代码- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position方法这是一个委托方法。所以,你应该在viewdidload中向委托确认。

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

多数民众赞。它只是工作!

解决第一个问题:

您无法识别一个视图上的两个滑动手势。 所以基本上,你的第一个问题的回答是不可能的。 您无法在pageview控制器中滑动SWRevealViewController

解决第二个问题:

HomescreenViewController ViewDidLoad方法中编写此代码。

 - (void)viewDidLoad { SWRevealViewController * revealController=[[SWRevealViewController alloc]init]; revealController = [self revealViewController]; [self.view addGestureRecognizer:revealController.panGestureRecognizer]; revealController.delegate=self; [revealController panGestureRecognizer]; [revealController tapGestureRecognizer]; [btnSideMenu addTarget:revealController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside]; } 

之后,将SWRevealViewController委托方法添加到HomescreenViewController

 - (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position { if (revealController.frontViewPosition == FrontViewPositionRight) { UIView *lockingView = [UIView new]; lockingView.translatesAutoresizingMaskIntoConstraints = NO; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:revealController action:@selector(revealToggle:)]; [lockingView addGestureRecognizer:tap]; [lockingView addGestureRecognizer:revealController.panGestureRecognizer]; [lockingView setTag:1000]; [revealController.frontViewController.view addSubview:lockingView]; lockingView.backgroundColor=[UIColor ClearColor]; NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(lockingView); [revealController.frontViewController.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"|[lockingView]|" options:0 metrics:nil views:viewsDictionary]]; [revealController.frontViewController.view addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[lockingView]|" options:0 metrics:nil views:viewsDictionary]]; [lockingView sizeToFit]; } else [[revealController.frontViewController.view viewWithTag:1000] removeFromSuperview]; } 

可能是,它会对你有所帮助。