2

我有一个 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 本身!

我错过了什么?

4

6 回答 6

3

您必须将 supportedDeviceOrientations 添加到您的 "myApp.plist" 。

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

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

于 2010-05-27T08:24:47.480 回答
1

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}
于 2010-09-10T09:59:01.380 回答
1

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

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

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

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

于 2012-09-26T20:33:06.380 回答
0

解决方案是添加密钥

UISupportedInterfaceOrientation

对你 Info.plist 有一个字符串数组,指定启动时支持的界面方向,这些是

  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight

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

于 2010-10-14T11:43:21.060 回答
0

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

[myViewController viewDidLoad];

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

于 2011-02-10T20:16:41.597 回答
0

试试这个

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
}
于 2010-09-16T10:07:52.070 回答