设置LaunchScreen.storyboard竖屏显示

有时候我们希望App启动页竖屏显示,其它页面既可以竖屏又可以横屏,而在使用LaunchScreen.storyboard作为启动页时,由于LaunchScreen.storyboard无法使用自定义的ViewController,所以也没办法覆盖supportedInterfaceOrientations属性来修改启动页支持的界面方向,这个时候我们可以将Info.plist设置为仅竖屏显示,然后在AppDelegate中设置为支持横竖屏。


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

下面是苹果对该方法的说明,意思是如果未实现此方法,则使用Info.plist里key为supported interface orientations的值作为App支持的界面方向,否则使用该方法返回值作为App支持的界面方向。

- (UIInterfaceOrientationMask)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window;
This method returns the total set of interface orientations supported by the app. When determining whether to rotate a particular view controller, the orientations returned by this method are intersected with the orientations supported by the root view controller or topmost presented view controller. The app and view controller must agree before the rotation is allowed.
If you do not implement this method, the app uses the values in the UIInterfaceOrientation key of the app’s Info.plist as the default interface orientations.

你可能感兴趣的:(设置LaunchScreen.storyboard竖屏显示)