【问题标题】:View controller doesn't autorotate to portrait upside down视图控制器不会自动旋转到纵向倒置
【发布时间】:2013-09-04 22:52:37
【问题描述】:

我已经为自动旋转实现了一个视图控制器。所以这个视图控制器,我称之为RotatableViewController,实现了这些方法:

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (BOOL) shouldAutorotate {
    return YES;
}

它应该自动旋转到所有方向,我还检查了目标中支持的界面方向:

但令人难以置信的是,它不会在纵向倒置方向上自动旋转:

可能是什么问题?

PS 在 iOS 6.1 中,视图控制器通过情节提要进行实例化。

【问题讨论】:

    标签: iphone ios objective-c autorotate


    【解决方案1】:

    问题是您使用的是UINavigationController,它在 iPhone 上默认不支持倒置。作为一般设计原则,iPhone 应用程序不应支持倒置(据称是因为 iPhone 上的“锁定”开关确实锁定了横向模式,这与 iPad 不同)。倒置方向仅适用于 iPad 设备。

    您可以通过子类化UINavigationController 并使用返回UIInterfaceOrientationMaskAllsupportedInterfaceOrientations 来解决您的问题,并将其指定为情节提要中导航控制器的基类。但我不认为你应该这样做,因为 iPhone 上的应用程序通常不支持倒置纵向。

    【讨论】:

      【解决方案2】:

      旧版本的 UIInterfaceOrientationMaskAll 存在问题。不确定您使用的是哪个版本。尝试重做所有方向。

      - (NSUInteger) supportedInterfaceOrientations
      {
          return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
      }
      

      【讨论】:

      • 好的。那么您的视图控制器接线是否正确? self.window.rootViewController = self.viewController;
      猜你喜欢
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多