侧边栏MMDrawerController简单实现抽屉
2017-03-13 本文已影响15人
七叶昔洛
侧边栏在app中非常常见, 这里就介绍一个非常实用的第三方库MMDrawerController, 使用非常方便,可以pods导入,也可以手动拖拽, 不过我习惯直接拖过来, 这样自己可以方便的修改里面的代码.
Untitled.gif
我们需要在APPdelegate里面导入头文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = WHITE_COLOR;
QYTabbarViewController *tabbarVC = [[QYTabbarViewController alloc] init];
QYLeftPageViewController *leftVC = [[QYLeftPageViewController alloc] init];
QYRightViewController *rightVC = [[QYRightViewController alloc] init];
self.mmdrawerVC = [[MMDrawerController alloc] initWithCenterViewController:tabbarVC leftDrawerViewController:leftVC rightDrawerViewController:rightVC];
[self.mmdrawerVC setShowsShadow:YES];//阴影
[self.mmdrawerVC setMaximumLeftDrawerWidth:SCREEN_WIDTH - 80];
[self.mmdrawerVC setMaximumRightDrawerWidth:SCREEN_WIDTH - 80];
[self.mmdrawerVC setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.mmdrawerVC setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
self.window.rootViewController = self.mmdrawerVC;
[self.window makeKeyAndVisible];
return YES;
}
这里已经基本上完成了, 我们在其他页面所关心的就是打开和关闭的操作
//关闭的方法
[appdelegate.mmdrawerVC closeDrawerAnimated:YES completion:^(BOOL finished) {
//设置打开抽屉模式为MMOpenDrawerGestureModeNone,也就是没有任何效果, 将页面拖拽手势关闭。
// [appdelegate.mmdrawerVC setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
}];
打开的方法 open 这里就不在赘述了.