2

Comrades,

I just would like to know, how to enable Landscape Orientation only on Specific screens? As of now, I selected Landscape Left and Right options in General Settings and enabled in Supported interface orientations (iPhone) in plist file for the device Orientation, but that impacts all the screens.

I have nearly 80 screens in my application, I need to support both Portrait and Landscape about 5 screens, rest of the screens should be shown only in Portrait mode.

Any help is greatly appreciated!

Thanks, Ramesh

Sam B
  • 27,273
  • 15
  • 84
  • 121
Ramesh Sangili
  • 1,633
  • 3
  • 17
  • 31
  • allow all orientations and then force portrait only on the ones you want ... see http://stackoverflow.com/questions/18988163/uiinterfaceorientation-landscape-vs-portrait-issue-in-xcode-5/18989506#18989506 – Sam B Mar 31 '14 at 18:03
  • You want to add it for each screen to force Portrait ? In other words, you want me to write it on 75 screens to force Portrait only? – Ramesh Sangili Mar 31 '14 at 18:28
  • Hi, I am building this application on a framework. Our framework extend UIViewController and we extend FramewworkUIViewController class to design the screen. I added a category to FrameworkUIViewCOntroller and added the supportedInterfaceOrientation to lock it only portrait mode, but that is not working :(... – Ramesh Sangili Mar 31 '14 at 19:57

2 Answers2

0

In General Settings (which just adjusts your plist), you need to select all possible supported orientations. Then, you need to limit them in your specific view controller. If you're using a NavBar or TabBar controller, you need add your limitation there.

From the UIViewController docs:

In iOS 6 and later, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Typically, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.

To make this simpler, I created a category on UINavigationController that looks at the top-most view controller to determine it's rotation abilities. That way, in my specific view controllers that needed rotating, I could override those same methods and add landscape support.

@implementation UINavigationController (AutoRotation)

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

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

@end
djibouti33
  • 12,102
  • 9
  • 83
  • 116
  • Sorry, do you want to add those two methods in all View Controllers? – Ramesh Sangili Mar 31 '14 at 17:35
  • 1
    Hi, I am building this application on a framework. Our framework extend UIViewController and we extend FramewworkUIViewController class to design the screen. I added a category to FrameworkUIViewCOntroller and added the supportedInterfaceOrientation to lock it only portrait mode, but that is not working :(... – Ramesh Sangili Mar 31 '14 at 19:57
  • I can't remember exactly what I did, but in my key view controllers (like a parent view controller, I set `shouldAutorotate` to false. Then in a child viewController, the one I want to rotate I set `shouldAutoRotate` to true. You can then also add `supportedInterfaceOrientations` to the child viewController to specify exactly which rotations you want to support. – djibouti33 Mar 31 '14 at 21:34
  • Do you load FrameworkUIViewController into a nav or tab controller? If so, the category has to be on UINavigationController/UITabBarController (like in the example above) and then the `shouldAutoRotate` declaration occurs within the specific view controller providing the content for the screen. As a controller, UINavigationController has it's own rotation rules, so by adding the category and placing the rotation specifics into a normal view controller, the nav controller gets it's rotation rules from it's topmost child. – djibouti33 Mar 31 '14 at 21:36
0

Are your screens inside a UINavigationController? If so, I've noticed not all viewControllers can decide what orientations they support.

rounak
  • 9,217
  • 3
  • 42
  • 59