防止一个视图控制器的自动旋转?

Rob*_*ert 16 objective-c uiviewcontroller autorotate ios ios6

我的应用程序可以自动旋转,但我需要其中一个视图仅以纵向模式显示,并且不知道如何实现此目的.

我试过这个(除其他事项外)但是有问题的观点仍然在旋转:

//  ViewController.m

-(BOOL)shouldAutorotate
{            
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

有人可以指出我做错了什么吗?谢谢.

-编辑-

它适用于iOS 6.1

Ani*_*ese 31

UINavigationController涉及a时,在UINavigationController和上创建一个类别override supportedInterfaceOrientations.

 #import "UINavigationController+Orientation.h"

 @implementation UINavigationController (Orientation)

-(NSUInteger)supportedInterfaceOrientations
{
   return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
 {
    return YES;
 }

@end  
Run Code Online (Sandbox Code Playgroud)

现在,iOS容器(例如UINavigationController)不会咨询他们的孩子以确定他们是否应该自动旋转.

如何创建类别
1.添加一个新的文件(下可可触摸目的的C类)
2 Category:方向上的UINavigationController
3.上面的代码添加到UINavigationController+Orientation.m