Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Disabling Landscape LaunchScreen.storyboard

I have an LaunchScreen.storybaord that shows a logo (textual so it is orientation agnostic). The app starts always in portrait, but it has certain view controllers that allow landscape mode (so making the app portrait only is not an option).

What I want is that the launch screen always comes up in portrait. So holding the phone in landscape during app start should result in seeing the logo rotated (as if looking at a view controller that does not support landscape)

Is there a way to tell the storyboard to be portrait only?

I tried to use size classes traits, but this way I can only address left OR right landscape. Since there is also an intro screen for first time users that animate the logo from launch screen, the logo rotation depends on which direction the phone was put in landscape.

like image 977
sofacoder Avatar asked Jun 08 '18 08:06

sofacoder


People also ask

How do I turn off landscape mode in iOS?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.

Can I delete Launchscreen storyboard?

You must have a launch screen, either provided by a storyboard or using images in an asset catalog. If you remove both of these then iOS will assume that your app doesn't support larger displays, which is why you are getting the black bars; your app is running in backward-compatibility mode.

How do I turn off landscape mode in Swift?

From the main screen, slide the top of the screen down. Then, slide the top of the screen down again. Tap the "Portrait" icon to enable landscape mode, or tap the "Auto rotate" icon to disable it. Note: When "Auto rotate" is enabled, the interface will rotate when you hold the phone horizontally.

How do I add Launchscreen to SwiftUI?

Adding a Launch Screen In SwiftUI projects, the launch screen is not generated by default. You need to add it manually in the Info. plist file. After opening the file, you should see an entry named Launch Screen.


1 Answers

There are several approaches to achieve this. My preferred one though is to specify in Info.plist

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>

And override this after app finished launching inside AppDelegate

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

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

like image 116
Sunil Avatar answered Oct 29 '22 01:10

Sunil