iOS 7.仅为一个视图控制器更改页面方向

ale*_*xjk 5 uiinterfaceorientation ios

我有iPhone应用程序,只支持纵向方向.我想添加到仅支持横向方向的项目视图控制器?可能吗?如果是的话我怎么能实现呢?

我试图像这样包装类别文件:

@implementation UINavigationController (Rotation_IOS7)

-(BOOL)shouldAutorotate
    {

        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {

      return UIInterfaceOrientationMaskLandscape;

    }
Run Code Online (Sandbox Code Playgroud)

如果我这样做,我会收到此错误:由于未捕获的异常而终止应用程序UIApplicationInvalidInterfaceOrientation,原因:Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

Suh*_*til 0

编辑:

在.h中创建一个类别,然后实现这些方法

在要支持横向的视图控制器中使用这些方法

@implementation UINavigationController (Rotation_IOS7)

-(BOOL)shouldAutorotate
    {

        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {

      return UIInterfaceOrientationMaskLandscape;

    }
Run Code Online (Sandbox Code Playgroud)