5

所以我最近遇到了这个非常简洁的库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 代码引起)。如何正确将此库与情节提要集成在一起?

4

4 回答 4

7

以下是需要做的:-

1) 在 Storyboard 中创建 3 个 View,并为每个 View 提供 Class 和 Storyboard ID。

2)在导航控制器中嵌入您的中心视图控制器,即单击您的中心视图,然后单击“编辑器”=>“嵌入”=>“导航控制器”

3)转到以下github链接:-

https://github.com/mutualmobile/MMDrawerController 并从那里下载文件 MMDrawerController Zip 文件。

4)通过右键单击您的项目并选择“将文件添加到”,将来自上述 github 项目的以下文件包含到您的项目中:-

  • MMExampleDrawerVisualStateManager.h
  • MMExampleDrawerVisualStateManager.m
  • MMDrawerBarButtonItem.h
  • MMDrawerBarButtonItem.m
  • MMDrawerController.h
  • MMDrawerController.m
  • MMDrawerController+Subclass.h
  • MMDrawerVisualState.h
  • MMDrawerVisualState.m
  • UIViewController+MMDrawerController.h
  • UIViewController+MMDrawerController.m

5) 最后转到 AppDelegate.m 文件并在 didFinishLaunchingWithOptions 函数中键入以下代码:-

Objective-C

UIStoryboard *storyboard;

storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * leftSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
 @"leftViewController"];

UIViewController * centerSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
 @"ViewController"];

UIViewController * rightSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
 @"rightViewController"];



self.drawerController =
[[MMDrawerController alloc]
 initWithCenterViewController:centerSideNavController
 leftDrawerViewController:leftSideNavController
 rightDrawerViewController:rightSideNavController];

[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];


[self.window setRootViewController:self.drawerController];
/* Optional - To define Drawer width */
[self.drawerController setMaximumRightDrawerWidth:280.0];

[self.drawerController setMaximumLeftDrawerWidth:280.0];

[self.window makeKeyAndVisible];

斯威夫特 2.2

let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let centerVC = mainStoryBoard.instantiateViewControllerWithIdentifier("Home") as! HomeVC

let leftVCs = mainStoryBoard.instantiateViewControllerWithIdentifier("Left") as! LeftVC

let rightVCs = mainStoryBoard.instantiateViewControllerWithIdentifier("Right") as! RightVC

let rightSideNav =  UINavigationController(rootViewController: rightVCs)
let leftSideNav =  UINavigationController(rootViewController: leftVCs)

let centerSideNav = UINavigationController(rootViewController: centerVC)

centerContainer = MMDrawerController(centerViewController: centerSideNav, leftDrawerViewController: leftSideNav, rightDrawerViewController: rightSideNav)

centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView
centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView
                  centerContainer?.setDrawerVisualStateBlock(MMDrawerVisualState.swingingDoorVisualStateBlock())

window!.rootViewController = centerContainer
window!.makeKeyAndVisible()

注意:在 Swift 版本的情况下,全局添加var centerContainer: MMDrawerController?到 AppDelegate 类中。

于 2015-08-27T10:50:58.950 回答
3

只是对遇见 Shah 的回答的补充,如果有人在中心控制器中缺少导航栏,那么只需在他的代码之间添加以下代码

UINavigationController * navigationController = [[UINavigationController alloc] 
    initWithRootViewController:centerSideNavController];
self.drawerController = [[MMDrawerController alloc]
     initWithCenterViewController:navigationController
     leftDrawerViewController:leftSideNavController
     rightDrawerViewController:rightSideNavController];

希望对某人有所帮助。

于 2016-02-25T08:33:39.093 回答
1

看看这个,https://github.com/TomSwift/MMDrawerController-Storyboard

它属于MMDrawerController带有故事板的魅力之类的作品类别!

于 2014-07-24T10:26:09.437 回答
1

如果你想要故事板中的抽屉而不是使用这个库,我已经在许多项目中使用了 抽屉

于 2014-05-08T04:58:18.753 回答