如何在Xcode中管理屏幕方向?

时间:2013-02-16 16:20:13

标签: iphone ios xcode

我的应用程序中有两个视图控制器 第一视图控制器是横向模式,第二视图控制器是横向模式。

即使我旋转iPhone,我也不想改变他们的方向。 我该怎么做?

2 个答案:

答案 0 :(得分:4)

在Xcode中,突出显示Project Navigator中的项目,然后在项目树中选择目标。打开“摘要”页面,然后转到“支持的接口方向”部分。取消单击您不希望应用程序支持的方向。

在故事板中,选择您的第一个视图控制器,转到属性检查器,并将方向设置为"纵向"在“模拟指标”部分中。现在选择第二个视图控制器,并将其方向设置为" landscape"。

在视图控制器代码中,实现

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

表示第一个视图控制器,

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

用于第二个视图控制器。这应该可以解决你的问题。

答案 1 :(得分:2)

在您的情况下,您有两个VC。因此,在以下方法中的两个VC中,只需处理您的方向。并对toInterfaceOrientation执行检查并返回YES。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
     // For your VC1
     if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
           return YES;
     // For your VC2
     /*
     if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
           return YES;  
     */

}