uiviewcontroller - iOS 6 ViewController 正在旋转但不应该

标签 uiviewcontroller ios6 xcode4.5

我希望我的几个应用 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/

相关文章:

ios - 如何防止每次加载 View Controller 时创建 AVAudioPlayer 类的新实例 - Swift

ios - 移除 View Controller 底部的灰色条 - iOS

ios - Segue 没有将数据传递到目的地

ios - 背景图像在 cocos2d 中没有正确滚动

xcode - 重复目标 : Xcode cannot run using the selected destination

objective-c - 点击文本字段时不显示键盘

ios - 隐藏键盘 IOS Swift

ios - 让 Swift 类同时充当 UIViewController 子类和 UITableViewDelegate

ios - 如何在我的网络服务中显示加载 View Controller

objective-c - gdb 远程返回错误 : E08 when calling completion block (EXC_BAD_ACCESS)