如何在iOS中仅为视图控制器设置纵向?

时间:2013-08-28 09:50:54

标签: iphone xcode ios6 view landscape

我的项目有很多视图控制器(.xib文件)。 我想:视图控制器只能有纵向方向。但是,其他视图控制器只能具有横向方向。或者视图控制器可以同时具有纵向和横向。 现在我希望视图控制器只有横向(没有纵向)。请帮我。谢谢你。

1 个答案:

答案 0 :(得分:0)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

<强>更新:

您可以通过创建UINaviagationController的类别

来完成此操作 .h文件的

代码是

@interface UINavigationController (autorotation)

-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;

和.m文件的代码是

 @implementation UINavigationController (autorotation)

    -(BOOL)shouldAutorotate
    {

        UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
        [self.topViewController shouldAutorotate];
        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;

    }
    @end