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!