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

查看:96
本文介绍了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。)在应用程序中设置windows rootviewController:didFinishLaunchingWithOptions:

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天全站免登陆