4

I have an iOS8 app that I need to support all orientations while playing the game, but while in the menus, is portrait only. I want the app to launch using only the portrait image, so it matches the portrait menus. The issue I'm having is that I have to set 'UISupportedInterfaceOrientations' in the Info.pList file to support all orientations, because I need them all for the main game. This obviously causes my app to launch in landscape mode if the device is sideways, which I don't want. I have tried to set the values in the info.pList file to portrait only, but this causes Landscape mode to stop working completely.

Is there a way to allow all orientations in the info.pList file, but force the launch image to portrait only? Or allow all orientations in my code, but specify only portrait values in the info.pList file?

Shaun Budhram
  • 3,690
  • 4
  • 30
  • 41
  • Good answer over here: http://stackoverflow.com/questions/25606442/how-to-lock-portrait-orientation-for-only-main-view-using-swift – Steve Rosenberg Oct 03 '14 at 05:05

4 Answers4

4

You should use 'Launch Screen File' for iOS 8 (Available in xCode 6+). And then apply constraints over the launch file as you wish (You can allow orientation for the launch xib in story builder as required). Even if you want it for previous version, create a separate splash screen and set its orientation properties in story builder.

ZaEeM ZaFaR
  • 1,508
  • 17
  • 22
2

I encountered this problem too and found a great solution from Apple itself:

https://developer.apple.com/library/ios/technotes/tn2244/_index.html#//apple_ref/doc/uid/DTS40009012-CH1-ALLOWING_YOUR_APP_TO_ROTATE_INTO_PORTRAIT_ORIENTATION_AFTER_LAUNCH

It says to check the desired launch orientation in the info.plist and then implement this delegate method in appdelegate to override the supported orientations after launch:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
    return .AllButUpsideDown
}
Janneman
  • 1,093
  • 15
  • 23
0

You can define a parent view controller with:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

And your rotating view controller with:

- (BOOL)shouldAutorotate {
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}
Eva Madrazo
  • 4,731
  • 2
  • 23
  • 33
0

There are two steps you have to follow for this:

1- You need to select only one desired orientation in your Info.plist file. And this selection will be applied to your launch screen. For your example case this should be UIInterfaceOrientationPortrait

2- You have to implement func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask in your AppDelegate. For your example case implementation should be

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return .all    
 }
moody
  • 151
  • 1
  • 5