MMDrawerController Library to work with storyboard
Asked Answered
W

4

5

So I've recently come across this pretty neat library, MMDrawerController. I've managed to install it and initialized it with the code below in 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;
}

However, everything in my storyboard is now covered in black (caused by the code above "overriding" storyboard's xml code)when I build the app. How can I properly integrate this library along with storyboard?

Work answered 8/5, 2014 at 4:49 Comment(4)
add [self.window makeKeyAndVisible];Bough
@Bough should I add this to the viewDidLoad in the viewControllers or add it into willFinishLaunchWithOptions in appDelegate?Work
add willFinishLaunchWithOptions,add next to [self.window setRootViewController:self.drawerController];Bough
@Bough Thank you for your inputs, I've added [self.window makeKeyAndVisible]; after [self.window setRootViewController:self.drawerController]; but the storyboard is still not being loaded or is being covered by the codeWork
S
7

Following is what needs to be done:-

1) Create 3 Views in your Storyboard and give both Class and Storyboard ID to each of them.

2) Embed your Centre View Controller in Navigation Controller i.e. Click on your Centre view and then click on "Editor" => "Embed In" => "Navigation Controller"

3) Go to following github link:-

https://github.com/mutualmobile/MMDrawerController and download file MMDrawerController Zip file from there.

4) Include following files from above github project to your project by right clicking your project and choosing "Add Files to " :-

  • 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) Finally go to AppDelegate.m file and within didFinishLaunchingWithOptions function type following code:-

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];

Swift 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()

Note: Add var centerContainer: MMDrawerController? within AppDelegate class globally in case of Swift version.

Sledgehammer answered 27/8, 2015 at 10:50 Comment(1)
Thank you so much. !! It's help me a lots.Galliot
W
1

if you want drawer in storyboard than used this library i already used in many projects Drawer.

Whereon answered 8/5, 2014 at 4:58 Comment(2)
I've used this before, but I find that MMDrawerController has much better features (just my opinion). I've tried bringViewToFront but the appDelegate method still overrides my storyboardWork
as per my view my suggestion is more easy and you don't need to write that much of code just three line and you done.Whereon
S
1

Have a look on this, https://github.com/TomSwift/MMDrawerController-Storyboard

Its a category for MMDrawerController works like a charm with storyboard!

Swarthy answered 24/7, 2014 at 10:26 Comment(0)
D
1

Just an addition to Meet Shah's answer, If some one is missing navigation bar in center controller then just add a below code in between his code

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

hope that helps some one.

Darien answered 25/2, 2016 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.