Sagrian
Sagrian

Reputation: 1048

Issues related to Landscape mode for only 1 screen in application

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?

Upvotes: 0

Views: 1168

Answers (2)

nhgrif
nhgrif

Reputation: 62072

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.

Upvotes: 1

StuartM
StuartM

Reputation: 6823

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:

Upvotes: 0

Related Questions