5

I am using MMDrawerController in my application from this link
I set the root ViewController in the AppDelegate this way:

    self.leftDrawerController = [[LeftDrawerViewController alloc] init];

    self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];

    // DrawerViewController setup
    self.drawerController = [[MMDrawerController alloc]
                             initWithCenterViewController:self.navigationController
                             leftDrawerViewController:self.leftDrawerController];
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

    [self.drawerController setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
        MMDrawerControllerDrawerVisualStateBlock block; block = [[DrawerVisualStateManager sharedManager] drawerVisualStateBlockForDrawerSide:drawerSide];
        if (block) {
            block(drawerController, drawerSide, percentVisible);
        }
    }];

    [self.window setRootViewController:self.drawerController];

I want to disable rotation in a specific ViewController, I am calling those methods and they are never called and the view still rotate:

//  ViewController.m

-(BOOL)shouldAutorotate {            
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

I guess the problem is coming from the rootViewController which is the MMDrawerViewController!
I already checked this and this and this but nothing helped.

Community
  • 1
  • 1
sazz
  • 3,193
  • 3
  • 23
  • 33

2 Answers2

3

in MMDrawerController override following methods something like.

-(BOOL)shouldAutorotate {            
    return [self.centerViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations {
    return [self.centerViewController supportedInterfaceOrientations];
 }

Try this if not successful then you need to subclass UINavigationController and override these methods then your viewcontrollers orientation settings would be passed in hierarchy.

Zahid
  • 552
  • 3
  • 11
  • I added those methods in the MMDrawerController, they didn't exist before. And in my ViewController I still can't disable the rotation. – sazz Mar 05 '15 at 14:03
  • now you would have to implement these methods in all of your view controllers to lock and unlock rotations for them. If issue still exist then you may have to subclass navigationcontroller and use these methods sending you format for navigationcontroller methods – Zahid Mar 05 '15 at 14:06
  • I implemented this in my ViewController, when the view is lunched the shouldAutorotate and the supportedInterfaceOrientations of the ViewController are called first, then those both methods are called in the MMDrawerController, the it still rotate – sazz Mar 05 '15 at 14:13
3

If issue still exist then subclass UINavigationController and implement

-(BOOL)shouldAutorotate {            
   return [self.topViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations {
   return [self.topViewController supportedInterfaceOrientations];
}

I think UINavigationController controls automatically but in case it dont you can subclass.

Zahid
  • 552
  • 3
  • 11