纠结了一天都不知道怎么在storyboard中用MMDrawerController,看了下MMDrawerController+Storyboard版本的库也不知道怎么用,
网上搜了下,发现了个好方法。
(参考 http://www.wenzizone.cn/?p=470 )
下面直接说步骤:
1.新建一个single view的工程
2.在工程目录下新建一个Podfile文件,并写好配置,在终端执行pod install命令
target :'MMDrawerController+StoryBoard_Code' do
platform :ios, '10.0'
pod 'MMDrawerController'
end
(关于如何使用cocoasPod,参考这里http://blog.csdn.net/wzzvictory/article/details/18737437,提一点,链接中提到的更改成淘宝镜像网站地址时,请使用https)
3.打开工程,新建一个ViewController,然后新建一个类继承UIViewController与新ViewController关联,别忘了为两个ViewController加上storyboardId(最右边)! 我是将左边栏的storyboardId命名为left_sb,中间view的storyboard命名为center_sb。
4.在APPDelegate.m中,添加代码
#import "AppDelegate.h"
#import <MMDrawerController.h>
@interface AppDelegate ()
@property (nonatomic, strong) MMDrawerController *mmDrawerController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.mmDrawerController = [[MMDrawerController alloc] initWithCenterViewController:[storyboard instantiateViewControllerWithIdentifier:@"center_sb"] leftDrawerViewController:[storyboard instantiateViewControllerWithIdentifier:@"left_sb"]];
[self.mmDrawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.mmDrawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.mmDrawerController setMaximumLeftDrawerWidth:160];
[self.mmDrawerController setShouldStretchDrawer:YES];
[self.mmDrawerController setShowsShadow:NO];
self.window.rootViewController = self.mmDrawerController;
return YES;
}
5.运行!