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 解决。
552



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



