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?
source to share
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.
source to share
I faced this problem too and found a great solution from Apple itself:
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
}
source to share
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;
}
source to share
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 }
source to share