Ios “做”;“支持的接口方向”;有先例吗?

Ios “做”;“支持的接口方向”;有先例吗?,ios,objective-c,autorotate,Ios,Objective C,Autorotate,我正在开发一个应用程序,我想一个屏幕自动旋转到景观 这将是应用程序中唯一的旋转屏幕 我想找到最简单的方法 如果我在build summary页面中设置了支持的方向(即使用切换按钮),使其仅为纵向。然后,我可以在要自动旋转的屏幕的代码中覆盖此选项吗 还是我必须反过来做?i、 e.支持所有方向,然后禁用所有我不想旋转的屏幕 谢谢 还是我必须反过来做?i、 e.支持所有方向,然后禁用所有我不想旋转的屏幕 对。您必须为Info.plist列出您将支持的所有方向。然后使用支持的界面方向限制特定的视图控制器

我正在开发一个应用程序,我想一个屏幕自动旋转到景观

这将是应用程序中唯一的旋转屏幕

我想找到最简单的方法

如果我在build summary页面中设置了支持的方向(即使用切换按钮),使其仅为纵向。然后,我可以在要自动旋转的屏幕的代码中覆盖此选项吗

还是我必须反过来做?i、 e.支持所有方向,然后禁用所有我不想旋转的屏幕

谢谢

还是我必须反过来做?i、 e.支持所有方向,然后禁用所有我不想旋转的屏幕

对。您必须为Info.plist列出您将支持的所有方向。然后使用
支持的界面方向
限制特定的视图控制器方向。必须显示一个横向视图控制器,即使用“模式”序列或调用
presentViewController:animated:

我在这里的回答可能有用:

我的回答是:


向要旋转的视图的viewDidLoad方法添加观察者,如下所示:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:

        break;
    case UIDeviceOrientationPortraitUpsideDown:

        break;
    case UIDeviceOrientationLandscapeLeft:

        break;
    case UIDeviceOrientationLandscapeRight:

        break;

    default:
        break;
  };
}
然后根据要在方向更改方法中更改的视图设置视图,如下所示:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:

        break;
    case UIDeviceOrientationPortraitUpsideDown:

        break;
    case UIDeviceOrientationLandscapeLeft:

        break;
    case UIDeviceOrientationLandscapeRight:

        break;

    default:
        break;
  };
}

在iOS 6中,应用程序支持的方向(在
Info.plist
中说明)与俯视控制器支持的方向一致,因此为了实现您想要的,您需要在
Info.plist
中声明对每个方向的支持,然后覆盖视图控制器中不希望发生旋转的
supportedOrientations:
方法,例如:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

如果只有一个视图控制器,它们是否相同?