1

My navigation stack looks like this:

[UINavigationController] ---> [ViewController1] ---> [ViewController2] ...

I want to lock ViewController1 in portrait orientation but ViewController2 can rotate freely.
I tried to put these line of codes in various places but they don't work.

-(BOOL)shouldAutorotate {
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

I also tried to sub-classing UINavigationController as well (accepted answer in few other questions with similiar issue) but nothing works.
I'm also having a left sidebar controller using MMDrawerViewController.

The problem is ViewController1 can still rotate to other orientations, after many attempts.
Anybody know how to fix this ? Thanks in advanced.

Pham Hoan
  • 2,107
  • 2
  • 20
  • 34
  • similar to what you wants. can modify in logic in answer http://stackoverflow.com/questions/25116967/youtube-video-directly-not-playing-to-landscape-mode-ios-7/25119235#25119235 – Mohit Aug 23 '14 at 07:33
  • Where exactly are you facing problems? Please be a little more elaborate. – n00bProgrammer Aug 23 '14 at 07:34
  • `n00bProgrammer` I've editted my question. `MohitPopat` ok, I'm going to try it now, but it seems to be not a good solution. – Pham Hoan Aug 23 '14 at 07:39
  • @PhamHoan yes you are right. i also write there not a great solution but helpful solution – Mohit Aug 23 '14 at 07:40
  • Subclassing should work and inside the `- (NSUInteger)supportedInterfaceOrientations` you can check the class of `self.topViewController` to return the correct mask, or call ` [self.topViewController supportedInterfaceOrientations];` from the navigationController. – Jkmn Aug 23 '14 at 08:14
  • @Jkmn not in my case, I don't know what's wrong. I even made a `UINavigationController` category and `import` it everywhere. Does nothing. I used this one: http://stackoverflow.com/questions/12520030/how-to-force-a-uiviewcontroller-to-portait-orientation-in-ios-6 – Pham Hoan Aug 23 '14 at 08:20

0 Answers0