iOS 中的屏幕旋转shouldAutorotate和supportedInterfaceOrientations的先后关系

时间:2023-03-09 18:10:41
iOS 中的屏幕旋转shouldAutorotate和supportedInterfaceOrientations的先后关系

这2个UIViewController的属性,都和旋转相关,

当设备发生旋转时,首先会查看根controller的shouldAutorotate是否允许旋转,如果允许,再通过

supportedInterfaceOrientations返回的方向 和 系统支持的方向 的交集,判断当前这个旋转是否应该发生。

系统支持的方向可以通过2个方法确定,一个是通过info.plist

iOS 中的屏幕旋转shouldAutorotate和supportedInterfaceOrientations的先后关系

第二种是通过

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

方法,第二种这种方法的优先级高,如果有同时设置,以第二种为准。