SWRevealViewController panGestureRecognizer with pageViewController iOS(滑动侧边菜单)

SWRevealViewController panGestureRecognizer with pageViewController iOS(side menu on swipe)

  1. 如果我已经在 frontViewController(在我的例子中是 HomescreenViewController)中有一些其他滑动手势,我如何使用 panGestureRecognizer 打开 sideMenu? 我的 frontViewController 包含一个 pageViewController,其中已为 pageViewController 启用了 5 pages.So 向左滑动和向右滑动。

    我在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;
    

    但这也不是 working.I 我正在使用最新的 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 方法中添加以下代码 这是一个委托 method.So,你应该在 viewdidload 中向委托确认。

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

那就是 it.It 很简单!

第一个问题的答案:

您无法在一个视图中识别两个滑动手势。所以基本上,不可能回答你的第一个问题。您无法在 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];
}

也许吧,对你有帮助。