【问题标题】:iPad launch orientation not detected未检测到 iPad 启动方向
【发布时间】:2010-04-27 14:48:25
【问题描述】:

我有一个 iPad 应用程序可以正常工作,但在启动期间出现了一个奇怪的问题。我已经阅读了几个关于方向的问题和答案,但这仍然让我感到困惑。

根视图控制器是一个带有 3 个选项卡的 UITabBarController。其中两个选项卡具有自定义视图控制器(一个基于 UIViewController,另一个基于 UITableViewController)并且都存在此启动方向问题。第三个选项卡是嵌入在 UINavigationController 中的自定义 UITableViewController。

好的,问题来了。如果我以纵向启动应用程序,一切正常。如果我以横向启动它,则第三个选项卡可以完美运行。但是,前 2 个选项卡以纵向显示,即使:

  1. 状态栏方向正确显示为横向(横跨屏幕)。
  2. 标签栏视图正确显示为横向,标签居中。
  3. 对于所有方向的 shouldAutorotateToInterfaceOrientation,所有视图都返回 YES。

如果我在视图控制器的 viewWillAppear 中调用 [self interfaceOrientation] 或 [[UIApplication sharedApplication] statusBarOrientation],则第三个选项卡的视图控制器报告 3(横向)但前两个视图控制器报告 1(纵向),即使状态酒吧显然是风景!

如果我将 iPad 旋转为纵向并返回横向,则所有 3 个选项卡的视图都正确旋转(并且上述方法按预期返回 3)。

此外,如果我点击任何其他选项卡,然后返回选项卡 #1 或 #2,那么它们现在将正确旋转,即使不旋转 iPad 本身!

我错过了什么?

【问题讨论】:

  • 也许我应该重写这个问题。简而言之,发生的情况是视图被旋转,但它们没有调整大小。所以在横向模式下,它们显示为横向,但屏幕的右侧是白色的,并且底部隐藏了一些视图。这只发生在我的视图直接嵌入到 Tab 控制器中时。如果我的视图位于 Tab 控制器内的 Navigation 控制器内,则它们的大小会正确调整。他们正确地收到了“willRotateTo...”和“didRotateFrom...”消息。它们旋转,只是不调整大小。

标签: iphone orientation ipad interface-orientation


【解决方案1】:

您必须将supportedDeviceOrientations 添加到您的“myApp.plist”中。

单击此列表,添加键“支持的界面方向”并添加支持的界面方向。这解决了我的问题。

有关更多信息,请点击此链接并转到“应用程序包”部分:http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html

【讨论】:

  • 谢谢,但我的 plist 中已经有 4 个值的“支持的界面方向(iPad)”和 1 个值的“支持的界面方向”(iPhone 版本只能垂直使用,但 iPad版本适用于任何方向)。我没有看到任何对supportedDeviceOrientations 的引用,所以我认为这是一个错字?
【解决方案2】:

我终于找到了答案:我只是在我的 LoadingController 中忘记了这个。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}

【讨论】:

    【解决方案3】:

    我发现设备方向一开始什么都没有。并且应该为未知返回 YES。这将允许它以正确的启动方向定位设备。

    这是我用来将此消息传播到旧消息的代码。

    - (BOOL)shouldAutorotate{
        UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
        if (orientation == UIDeviceOrientationUnknown) return YES;
        BOOL result = [self shouldAutorotateToInterfaceOrientation:orientation];
        return result;
    }
    

    请注意,如果方向 == UIDeviceOrientationUnknown,我会返回 YES。这纠正了我的加载问题。

    【讨论】:

      【解决方案4】:

      解决办法是加一个键

      UISupportedInterfaceOrientation

      Info.plist 包含一组字符串,用于指定启动时支持的界面方向,这些是

      • UIInterfaceOrientationPortrait
      • UIInterfaceOrientationPortraitUpsideDown
      • UIInterfaceOrientationLandscapeLeft
      • UIInterfaceOrientationLandscapeRight

      但是,有以下问题可能会导致混淆: 至少对于 XCode 3.2.4 中的 SDK 3.2 和 iPad 模拟器,我发现(至少某些)Info.plist 设置似乎在安装应用程序时被缓存和/或不更新。也就是说,添加上面的密钥并在模拟器中安装和启动应用程序没有效果。但是,从模拟器中删除应用程序解决了新安装的应用程序按指定行为的问题。

      【讨论】:

        【解决方案5】:

        在您的应用委托的 applicationDidFinishLaunchingWithOptions: 方法中,将视图控制器的视图添加到窗口后,添加以下内容:

        [myViewController viewDidLoad];
        

        如有必要,这将触发对 shouldAutorotateToInterfaceOrientation: 方法的调用。

        【讨论】:

          【解决方案6】:

          试试这个

          - (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
              return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-03-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多