【问题标题】:Do "Supported Interface Orientations" have precedent?“支持的界面方向”有先例吗?
【发布时间】:2013-04-28 21:06:57
【问题描述】:

我正在开发一个应用程序,我希望一个屏幕自动旋转为横向。

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

我正在尝试找到最简单的方法。

如果我在构建摘要页面中设置支持的方向(即使用切换按钮),使其只是纵向。然后我可以在我想要自动旋转的屏幕的代码中覆盖它吗?

或者我必须反过来做吗?即支持所有方向,然后禁用我不想旋转的所有屏幕?

谢谢

【问题讨论】:

    标签: ios objective-c autorotate


    【解决方案1】:

    或者我必须反过来做吗?即支持所有方向,然后禁用我不想旋转的所有屏幕?

    是的。您必须为 Info.plist 所有列出您将支持的方向。然后使用supportedInterfaceOrientations 限制特定的视图控制器方向。必须呈现您的一个横向视图控制器,即使用“模态”segue 或致电presentViewController:animated:

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

    https://stackoverflow.com/a/13755923/341994

    我的回答在这里:

    https://stackoverflow.com/a/15301322/341994

    【讨论】:

    • 如果只有一个视图控制器,它们是否相同?
    【解决方案2】:

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

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]
     addObserver:self selector:@selector(orientationChanged:)
     name:UIDeviceOrientationDidChangeNotification
     object:[UIDevice currentDevice]];
    

    然后根据您要在 orientationChanged 方法中更改的视图设置视图,如下所示:

    - (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;
      };
    }
    

    【讨论】:

      【解决方案3】:

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

      - (NSUInteger)supportedInterfaceOrientations
      {
          return UIInterfaceOrientationMaskPortrait;
      }
      

      【讨论】:

        猜你喜欢
        • 2011-05-16
        • 2015-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多