所以我最近遇到了这个非常整洁的库,MMDrawerController。我已经设法安装它并使用appDelegate.m中的代码初始化它。
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIViewController * leftSideDrawerViewController = [[LeftViewController alloc] init];
UIViewController * centerViewController = [[CenterViewController alloc] init];
UIViewController * rightSideDrawerViewController = [[RightViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
[navigationController setRestorationIdentifier:@"MMExampleCenterNavigationControllerRestorationKey"];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController
rightDrawerViewController:rightSideDrawerViewController];
[self.drawerController setRestorationIdentifier:@"MMDrawer"];
[self.drawerController setMaximumRightDrawerWidth:200.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block){
block(drawerController, drawerSide, percentVisible);
}
}];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.drawerController];
return YES;
}
然而,当我构建应用程序时,我的故事板中的所有内容现在都被黑色覆盖(由上面的代码“覆盖”故事板的xml代码引起)。如何将此库与故事板正确集成?
答案 0 :(得分:3)
只是对Meet Shah的回答的补充,如果有人在中央控制器中缺少导航栏,那么只需在他的代码之间添加以下代码
UINavigationController * navigationController = [[UINavigationController alloc]
initWithRootViewController:centerSideNavController];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideNavController
rightDrawerViewController:rightSideNavController];
希望对某人有所帮助。
答案 1 :(得分:1)
如果你想在故事板中使用抽屉而不是使用这个库已经在许多项目Drawer中使用过。
答案 2 :(得分:1)
看一下,https://github.com/TomSwift/MMDrawerController-Storyboard
它的MMDrawerController
类别就像故事板的魅力一样!