shouldAutorotate传播到modal viewcontrolleriOS6深处的正确方法是什么
考虑以下示例:
Tabbed Application在 XCode 4.5 中创建一个新示例- 在 中
Summary,选择所有方向 创建一个新的简单
UITabBarController,例如MyTabBarViewController并添加代码- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; }在 AppDelegate 中,替换为
UITabBarControllerbyMyTabBarViewController以挂钩旋转self.tabBarController = [[MyTabBarViewController alloc] init];现在旋转应该可以工作了,并在 中
FirstViewController添加代码以在单击时显示模态视图控制器-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UIViewController * viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil]; [self presentViewController: [[UINavigationController alloc] initWithRootViewController:viewController2] animated:YES completion:nil]; }
问题:
现在由于SecondViewController被 a 包裹UINavigationController,即使我已经添加shouldAutorotate到 SecondViewController 中,也无法正确完成倒置旋转。
唯一的解决方法是创建一个自定义UINavigationController并实现shouldAutorotate,这应该可以工作。
但是这种方法听起来很愚蠢,它需要我通过实现来修复所有 UI 类shouldAutorotate,我不能再使用速记[UINavigationController alloc]
initWithRootViewController...,我必须实现所有这些UITabBarController和UINavigationController.
有没有更好的方法?