Question

My app build with ECSlidingViewController 2.0 as the sliding menu. I would like to disable the rotate for only one UIViewController . all my UIViewController start with UINavigationController.

I have make a SubClass of UINavigationController to implement the methods and assign the subclass to all UINavigationController in the sotryboard. but it does not work. it seems the code not triggered.

Inside MyNavigationController.m :

#import "MyNavigationController.h"
#import "ContactUsViewController.h"

@interface MyNavigationController ()

@end

@implementation MyNavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (BOOL)shouldAutorotate {

    NSLog(self.topViewController.description);
    if ([self.topViewController isMemberOfClass:[ContactUsViewController class]]){
        return NO;
    }else{
        return YES;
    }

}

@end

ContactUsViewController is the UIViewController i don't want to rotate.

Was it helpful?

Solution

5 steps (I am running with Storyboard and IOS 7)

  1. Subclass the ECSlidingViewController. (eg. MyECSlidingViewController)
  2. Create your own shouldAutorotate and supportedInterfaceOrientations in the MyECSlidingViewController.
  3. SubClass the UINavigationController and assign to all your existing UINavigationController. (eg. MyNavigationController)
  4. Create your own shouldAutorotate and supportedInterfaceOrientations in the MyNavigationController.
  5. in the UIViewController you want to set to Portrait only.

MyECSlidingViewController.m

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

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

}

MyNavigationController.m

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

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

YourViewController.m

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

Hope it helps !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top