MMDrawerController 的使用

时间:2024-01-09 11:19:02

1.AppDelegate

.h 文件:#import "MMDrawerController .h"

@property (strong, nonatomic) MMDrawerController *drawerController;

.m文件:#improt "LeftViewController.h"

#import "rightViewController.h"

//创建窗口

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

//讲ViewController设置导航控制器根视图

UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:

[[ViewController alloc] init]];

//初始化左侧和右侧的视图控制器

LeftViewController *leftViewController = [[LeftViewController alloc] init];

RightViewController *rightViewController = [[RightViewController alloc] init];

//滑动的设置:以leftViewController为左滑动,以rightViewController为右滑动

self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:navigation leftDrawerViewController:leftViewController rightDrawerViewController:rightViewController];

//设置左右滑动的宽度

[self.drawerController setMaximumLeftDrawerWidth:360];

[self.drawerController setMaximumRightDrawerWidth:340];

//添加滑动手势

[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];

[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

//赋予权限

self.window.rootViewController = self.drawerController;

ViewController (视图控制器)

#import "AppDelegate.h"

#define SharApp ((AppDelegate *)[[UIApplication sharedApplication] delegate])  或者(AppDelegate *SharApp =

[UIApplication sharedApplication].delegate;)

//自定义按钮

#pragma mark -右滑动

- (void) rightButtonAction:(UIButton *) button{

[delegate.drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];

}

#pragma mark -左滑动

- (void) SearchButtonAction:(UIButton *) button {

[SharApp.drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];

}

#pragma mark -关闭

- (void) exitButtonAction:(UIButton *) button {

if(MMDrawerSideNone){

return ;

}

//[SharApp.drawerController toggleDrawerSide:MMDrawerSideNone animated:YES completion:nil];

[SharApp.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

}