0

I have many view controllers in my app (which supports all orientations). Some of those view controllers have content that is too much to fit in landscape. How can I limit some of my views to portrait while also having some portrait and landscape.

P.S. I'm using objective-C, and i've seen a lot of swift answers but I'm not good at translating Swift->Obj-C

Minebomber
  • 1,209
  • 2
  • 12
  • 35

1 Answers1

1

It depends on how your view controller hierarchy is set up.

For example, if you have a UINavigationController as your window's rootViewController, you can have a UINavigationControllerDelegate which returns the navigation controller's topViewController.supportedInterfaceOrientations. Then in your portrait-only view controllers, you would return UIInterfaceOrientationMaskPotrait in supportedInterfaceOrientations, and UIInterfaceOrientationMaskAll in the rest of your view controllers.

See here: https://stackoverflow.com/a/27623947/1812788

Community
  • 1
  • 1
Tamás Zahola
  • 9,271
  • 4
  • 34
  • 46
  • I tried to do `- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }` but that did nothing. Am I doing it right? – Minebomber Oct 11 '15 at 16:39
  • Do you use a UINavigationController as `window.rootViewController` ? Because in that case, you need a delegate for that navigation controller and implement `- navigationControllerSupportedInterfaceOrientations:` by querying the navigation controller's `topViewController` for supported orientations. The `UINavigationController` won't do that by default. (see the attached StackOverflow link) – Tamás Zahola Oct 11 '15 at 16:42