带侧边菜单的页面查看器(导航抽屉)

时间:2016-03-12 16:44:51

标签: ios objective-c navigation-drawer uipageviewcontroller

我使用REFrostedViewController作为侧边菜单控制器,问题是这个菜单会从屏幕的任何一点出现,我希望它像Android版本一样,只有当你开始从从屏幕左侧开始,如果从任何其他点滑动,菜单将不会出现。

我想要这个,因为我在这个菜单中有一个页面查看器。 由于我是IOS的新手,我查看了库代码并没有找到任何定义起点的函数也尝试修改消息 panGestureRecognized它不起作用。

所以我想建议一个帮助或任何其他有选择权的图书馆。

1 个答案:

答案 0 :(得分:2)

如果您已关注此库,那么我认为您已将此代码也放在

In ViewDidLoad

    [self.view addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)]];

And 

- (void)panGestureRecognized:(UIPanGestureRecognizer *)sender
{
    // Dismiss keyboard (optional)
    //
    [self.view endEditing:YES];
    [self.frostedViewController.view endEditing:YES];

    // Present the view controller
    //
    [self.frostedViewController panGestureRecognized:sender];
}

将以上代码替换为以下代码。

Confirm UIGestureRecognizerDelegate Delegate protocol

@interface DEMONavigationController () <UIGestureRecognizerDelegate>

In ViewDidLoad

    UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftEdgeGesture:)];
    leftEdgeGesture.edges = UIRectEdgeLeft;
    leftEdgeGesture.delegate = self;
    [self.view addGestureRecognizer:leftEdgeGesture];}

And
- (void)handleLeftEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture {

    if(UIGestureRecognizerStateBegan == gesture.state ||
       UIGestureRecognizerStateChanged == gesture.state) {
        [self.frostedViewController presentMenuViewController];


    }else{
        // DO nothing
    }
}