Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MMDrawerConroller how to disable rotation is some ViewControllers?

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.

like image 583
sazz Avatar asked Mar 05 '15 11:03

sazz


1 Answers

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.

like image 79
Zahid Avatar answered Nov 15 '22 05:11

Zahid