Handling Orientation
If you are using an app with a portrait main menu and landscape gameplay, this article will help you understand how to make your application orientation work correctly with the OS UI.
This page is only needed if you have a game with landscape gameplay and plan to use a portrait main menu or have other views/scenes that render in portrait. If your game is designed for portrait-only or landscape-only, these instructions do not apply.
- Unity/C#
- iOS/Swift
- iOS/Objective-C
- Android
To make sure that the OS menu bar renders correctly, make sure that any UIViewControllers
you use have their supportedInterfaceOrientations
function declared. For example for a landscape view you would want to have the following:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
and for the portrait view the view controller should have the following:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
To make sure that the OS menu bar renders correctly, make sure that any UIViewControllers
you use have their supportedInterfaceOrientations
function overridden. For example for a landscape view you would want to have the following:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.landscape
}
and for the portrait view the view controller should have the following:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
The Android SDK works using Android Activities, defined in your manifest through skillz_game_activity
and skillz_exit_activity
. You are responsible for making sure that your activities are declared with your desired android:screenOrientation
settings inside of the app's AndroidManifest.xml
.
If you use a mix of landscape and portrait views (such as having a portrait main-menu and landscape in-game views) you can control the screen orientation by setting Screen.orientation
. (Ex: a landscape view that uses Screen.orientation = ScreenOrientation.Landscape;
).
You must allow for the portrait orientation from the Unity editor, then when transitioning to your gameplay, you will want to restrict the user from rotating into portrait while playing to prevent your UI from distorting.