0

Application is portrait locked but there is this only video screen when I need to allow landscape orientation as well. My implementation is as follows:

in project file

orientation setting

Created custom navigation controller and overridden following methods :

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

Now lets say in application I have 4 view controllers as follows :

  1. Home view controller (portrait locked)
  2. List view controller (portrait locked)
  3. Video view controller (portrait + landscape)
  4. Settings view controller (portrait locked)

So in each view controller overridden

- (NSUInteger)supportedInterfaceOrientations
{
}

and returned UIInterfaceOrientationMaskPortrait or UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight depending on the view controller support.

I am using storyboard and Xcode 5.0.2 Our custom Navigation controller is root view controller. Home is on top of it, and in view will appear depending on count of some maintained list we either stay or navigate to List View controller using push segue.

From Video and setting view controller we have unwind segue which is connected to Home View controller.

If I go from portrait(Video) to setting, it remains portrait locked as expected.

Problems :

  1. If video is in landscape and then we move to Settings, settings is launched in landscape mode. If rotated once, then it becomes locked to portrait.
  2. In launch sequence as per implementation from Home if list count is 0 we move to List view controller. In this case viewWillAppear of List controller is called properly. But, lets say we are on Video in landscape and unwind segue is called, we are properly navigated from Home n then to List View Controller but viewWillAppear is not called in this particular scenario.

Some has suggested to implement shoudAutorotate as well. Have tried to return NO from portrait screens and YES from video View Controller (Trivially shouldAutorotate is implemented for custom navigation controller like supportedInterfaceOrientations implementation). But with this if steps from Problem 1 are followed, setting screen gets locked to landscape.

If there is any other suggestion? or is something missing?

Sagrian
  • 1,048
  • 2
  • 11
  • 29
  • Issue 1. I think that is expected - http://stackoverflow.com/questions/11366929/force-rotate-uiviewcontroller – StuartM Feb 04 '14 at 14:56
  • Yeah for issue 1, I'd suggest only presenting the user with the option to switch view controllers only when the video view is in portrait mode. – Lyndsey Scott Feb 04 '14 at 15:14

2 Answers2

1

If I understand the problem correctly, this is the method you're looking for:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

If you give your view controllers a preferred interface orientation, they will try to start at that orientation and then rotate to the appropriate orientation based on the supported interface orientations and whether or not auto-rotate is allowed for the view controller in question.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • Hey I tried this. I implemented above in all the view controllers and in my custom Navigation Controller as well in which Im sending the preferred orientation of last view controller from view controller array. getting same result though and it did not solve the problem. – Sagrian Feb 18 '14 at 09:31
0

Issue 1, I believe is expected behaviour: Source: Force Rotate UIViewController

Bottom line, if you have a view that only accepts landscape, you can use the following to force iOS to change the orientation. It's curious, but it works. I apologize that I can't give credit to the original author, but once came across this elsewhere on StackOverflow:

Issue 2, I believe you can use the relevant UINavigationController methods instead: navigationController:willShowViewController:animated:

Community
  • 1
  • 1
StuartM
  • 6,743
  • 18
  • 84
  • 160