ios如何让启动页(闪屏页)强制竖屏,而进入App后允许横屏和竖屏

1、修改App-info.plist(在XCode中General中设置 一样的效果)

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

2、AppDelegate中添加方法

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

贴一下苹果对这个的解释,可以放心使用:
Discussion
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.

翻译:
该方法返回应用程序支持的接口方向的总集合。在决定是否旋转某个特定视图控制器时,该方法返回的方向与根视图控制器或最上层呈现的视图控制器支持的方向相交。在允许旋转之前,app和视图控制器必须达成一致。

如果你不实现这个方法,应用会使用应用信息的UIInterfaceOrientation键中的值。作为默认的接口方向。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容