关于iOS的屏幕旋转的问题

本文介绍了iOS中控制屏幕旋转的方法,包括Info.plist设置、- (BOOL)shouldAutorotate及-(UIInterfaceOrientationMask)supportedInterfaceOrientations等。全局控制可以通过Info.plist和UIViewController实现,而在iOS6及以上版本,UINavigationController和UITabBarController的子控制器需特别处理。屏幕旋转的最终方向由这三者的交集决定,错误的配置可能导致应用崩溃。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新建工程后,旋转的设置大多是如图

此时,屏幕旋转都是按照此设置的方向旋转的,- (BOOL)shouldAutorotate 等没有响应

如要设置每页不同的旋转方向,需要打开如下设置

此时将根据

1. - (BOOL)shouldAutorotate 是否可以自动旋转

2. - (UIInterfaceOrientationMask)supportedInterfaceOrientations 可旋转的方向

 

为什么?那就先说说怎么控制屏幕旋转,如何决定Interface Orientation

 

首先,全局控制

方式一Info.plist文件中,有一个Supported Interface Orientations,可以配置整个应用的屏幕方向,此处为全局控制。

例:Info.plist 关于旋转的设置

 

   <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值