話很少說,先上圖
app
具體代碼實現:ide
1,在AppDelegate中:spa
#import "AppDelegate.h".net
#import "MMDrawerController.h"3d
#import "ViewController.h"orm
#import "LeftViewController.h"get
@interface AppDelegate ()it
@end io
@implementation AppDelegateclass
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
ViewController *centerVC = [[ViewController alloc]init];
UINavigationController *centerNav = [[UINavigationController alloc]initWithRootViewController:centerVC];
LeftViewController *leftVc = [[LeftViewController alloc]init];
MMDrawerController *rootVc = [[MMDrawerController alloc]initWithCenterViewController:centerNav leftDrawerViewController:leftVc];
[rootVc setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[rootVc setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
_window.rootViewController = rootVc;
[_window makeKeyAndVisible];
return YES;
}
2,在ViewController中:
#import "ViewController.h"
#import "MMDrawerController.h"
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(leftAction)];
self.view.backgroundColor = [UIColor redColor];
}
-(void)leftAction{
MMDrawerController *drawVc = (MMDrawerController *)[UIApplication sharedApplication].keyWindow.rootViewController;
[drawVc toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
3,建立LeftViewController
#import "LeftViewController.h"
@interface LeftViewController ()
@end
@implementation LeftViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
}