我希望我的几个应用 View Controller 在 iOS 6.0 中不旋转。
这就是我为使 iOS 6 中的旋转成为可能所做的工作:
1.) 在 application:didFinishLaunchingWithOptions 中设置 windows rootviewController:
self.window.rootViewController = self.tabBarController;
2.) 在我的目标(在 XCode 中)中设置“支持的界面方向”,以便我可以使用所有方向
3.) 实现了新的 iOS 6.0 旋转功能
- (BOOL) shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
4.) 由于某些原因,我继承了 UINavigationController 并实现了这些新功能,并使用了这个新的 NavigationController 而不是原来的。
到目前为止一切顺利,一切正常,所有 View Controller 现在都能够旋转到每个方向。现在我希望几个 viewController 不旋转而只保持纵向。但是当我在这些特定的 View Controller 中设置新的旋转方法时,它仍然会旋转到每个方向:
- (BOOL) shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
同样像上面一样设置 navigationController 的旋转功能不会改变任何东西。 (所有 View Controller 都可以旋转到每个方向)
我究竟做错了什么?
编辑:
同样设置首选的 Interfaceorientation 不会改变任何东西:
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
最佳答案
如果您希望我们所有的导航 Controller 都尊重顶 View Controller ,您可以使用一个类别。我发现它比子类化更容易。
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
关于uiviewcontroller - iOS 6 ViewController 正在旋转但不应该,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12526410/