MMDrawerController如何只让指定ViewController起作用

MMDrawerController是一个能实现抽屉效果的第三方库,其中主要三个元素吧:rightNavigationController、centerNavigationController、drawerController。前两个都是普通的NavigationController,可以往上面对各种ViewController进行push和pop;最后那个就是MMDrawerController的实例。用的时候就是

UIViewController *rightSideViewController = [[RightViewController alloc]init];
    UINavigationController *rightNavigationController = [[UINavigationController alloc]initWithRootViewController:rightSideViewController];
    
    UIViewController *centerViewController = [[CenterViewController alloc]init];
    UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:centerViewController];
    
    MMDrawerController *drawerController = [[MMDrawerController alloc]initWithCenterViewController:navigationController rightDrawerViewController:rightNavigationController];
    [drawerController setMaximumRightDrawerWidth:ScreenWidth*2/3];
    [drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    
    [drawerController
     setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
         MMDrawerControllerDrawerVisualStateBlock block;
         block = [MMDrawerVisualState parallaxVisualStateBlockWithParallaxFactor:2.0];
         if(block){
             block(drawerController, drawerSide, percentVisible);
         }
     }];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:drawerController];

很好理解,不过会伴随这样的问题:活动的效果时添加在一个NavigationController上的,所以在这个导航控制器中push进来的视图控制器都会识别这个抽屉提供的手势!

比如,上面的代码中,navigationController中当前添加的事视图控制器是centerViewController,称之为一级界面,由于某种触发,向navigationController中push了另个界面,videoController

[self.navigationController pushViewController:videoController animated:YES];
称这个videoController为二级界面,需求设定是:只让一级界面时会产生drawer效果,二级界面不产生;如果按照现在的情况,二级界面还是会有drawer效果,因为这个效果都是添加到了同一导航控制器上的。

搞明白bug的原因就好办了!

得,不废话了,如果只想在一级界面drawer效果,只需要在一级界面改动就好:

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
//...
    [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.mm_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    
}

-(void)viewDidDisappear:(BOOL)animated
{
    [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
    [self.mm_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];
}


原理就是在本界面出现时,所有手势可用,在本界面消失时,所有手势禁止

done!





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值