Force launch orientation of an app that supports all orientations

I have an iOS8 app that needs to be supported in all games, but there is only portrait in the menu. I want the app to launch using portrait only, so it matches portraits. The problem I'm running into 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 clearly forces my app to launch in landscape mode if the device is sideways, which is not what I want. I tried setting the values ​​in the info.pList file to portraits 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 only be in portrait? Or allow all orientations in my code, but only include portrait values ​​in the info.pList file?

+3


source to share


4 answers


You should use Run Screen File for iOS 8 (available in xCode 6+). And then apply launchfile restrictions as you wish (you can allow orientation for xib launch in history builder as needed). Even if you want it for the previous version, create a separate splash screen and set its orientation properties in the story builder.



+4


source


I faced 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



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

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
    return .AllButUpsideDown
}

      

+2


source


You can define the parent view controller with:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

      

And your rotary controller with:

- (BOOL)shouldAutorotate {
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

      

0


source


There are two steps you must follow to do this:

1- You only need to select one desired orientation in your file Info.plist

. And that selection will be applied to your launch screen. For your example, it should beUIInterfaceOrientationPortrait

2- You must implement func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) β†’ UIInterfaceOrientationMask

in your AppDelegate

. For your example, the case implementation should be

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

Run codeHide result


0


source







All Articles