屏幕旋转
iOS屏幕旋转
在设置某个特定的界面可以横屏的时候,跟UINavigationController,UITabbarController相关的控制器,会默认走基类的转屏方法,自己写的不会生效。故要把转屏的控制权交给跟控制器。在子Controller中定义转屏的方向。
/// 跟控制器是UINavigationController /// 是否允许转屏 - (BOOL)shouldAutorotate { return YES; } /// 支持的方向 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return [self.viewControllers.lastObject supportedInterfaceOrientations]; } /// 模态时的方向 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return self.topViewController.preferredInterfaceOrientationForPresentation; }
1 /// 跟控制器是UITabBarController时 2 - (BOOL)shouldAutorotate 3 { 4 return YES; 5 } 6 7 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { 8 return ((UINavigationController *)self.selectedViewController).topViewController.supportedInterfaceOrientations; 9 } 10 11 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 12 return ((UINavigationController *)self.selectedViewController).topViewController.preferredInterfaceOrientationForPresentation; 13 }