iOS 6 SDK 中的屏幕自动旋转有了一些变化,简单纪录之。举例:Master-Detail 类型 App,master ViewController 不支持屏幕旋转, detail ViewController 支持屏幕旋转。
在 Info.plist 或 Target-Summary 启用自动旋转,选中需要的 Supported Interface Orientations。新建 UINavigationController+Autorotation.h category,根据需要禁用最底层 NavController 的自动旋转:
在 AppDelegate 设置 window.rootViewController
= navController;,由于 shouldAutorotateToInterfaceOrientation: 从
iOS 6 起 deprecated,在需要自动旋转的 viewController 改用 supportedInterfaceOrientations+preferredInterfaceOrientationForPresentation。
几个需要注意的地方:
-
window 需要设置 rootViewController,
[window addSubview:navController.view];无效; -
shouldAutorotate在最底层设置才有效; -
presentModalViewController下用之前的自动旋转控制无效,须用 category 解决。
http://fann.im/blog/2012/10/22/autorotation-changes-in-ios-6/
本文详细介绍了iOS6 SDK中屏幕自动旋转的变化,并提供了Master-Detail类型应用的具体实现案例。通过设置 UINavigationController 的 category 和使用 supportedInterfaceOrientations 与 preferredInterfaceOrientationForPresentation 方法,实现了不同视图控制器的不同旋转需求。
4845

被折叠的 条评论
为什么被折叠?



