iOS 6 ViewController 正在旋转但不应该 [英] iOS 6 ViewController is rotating but shouldn't

查看:16
本文介绍了iOS 6 ViewController 正在旋转但不应该的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的几个应用视图控制器在 iOS 6.0 中不旋转.这就是我为使 iOS 6 中的旋转成为可能所做的工作:

I want several of my app viewcontrollers to not rotate in iOS 6.0. This is what i did to make the rotation in iOS 6 possible:

1.) 在 application:didFinishLaunchingWithOptions: 中设置 windows rootviewController:

1.) Set the windows rootviewController in application:didFinishLaunchingWithOptions:

self.window.rootViewController = self.tabBarController;

2.) 在我的目标(在 XCode 中)中设置支持的界面方向",以便我可以使用所有方向

2.) Set the "Supported Interface Orientations" in my Target (in XCode) so i can use all orientations

3.) 实现了新的 iOS 6.0 旋转功能

3.) Implemented the new iOS 6.0 rotation functionality

- (BOOL) shouldAutorotate {

    return YES;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

4.) 出于某些原因,我继承了 UINavigationController 并实现了这些新功能,并使用了这个新的 NavigationController 而不是原来的.

4.) For some reasons, i subclassed the UINavigationController and implemented also these new functionalities and used this new NavigationController in stead of the original one.

到目前为止一切都很好,一切正常,所有的视图控制器现在都能够旋转到每个方向.现在我想要几个 viewController 不旋转而只保持纵向.但是当我在这些特定的视图控制器中设置新的旋转方法时,它仍然会旋转到每个方向:

So far so good, everything works fine and all viewcontrollers are now able to rotate to every orientation. Now i want several viewController to not rotate and only stay in portrait. But when i set the new rotations methods in those specific viewcontrollers like this, it still rotates to every orientation:

- (BOOL) shouldAutorotate {

    return NO;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}

也像上面一样设置 navigationController 的旋转功能不会改变任何东西.(所有视图控制器都可以旋转到每个方向)

Also setting the navigationController's rotationsfunctionality like above doesn't change anything. (All viewcontrollers can rotate to every orientation)

我做错了什么?

同样设置首选的 Interfaceorientation 不会改变任何东西:

Also setting the preferred Interfaceorientation doesn't change anything:

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationMaskPortrait;
}

推荐答案

如果您希望我们所有的导航控制器都遵循顶视图控制器,您可以使用类别.我发现它比子类化更容易.

If you want all of our navigation controllers to respect the top view controller you can use a category. I've found it easier than subclassing.

@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

这篇关于iOS 6 ViewController 正在旋转但不应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆