未检测到 iPad 启动方向

发布于 2024-08-30 15:06:36 字数 818 浏览 10 评论 0原文

我有一个 iPad 应用程序,除了启动过程中出现奇怪的问题外,它运行正常。我读过几个问题&关于方向的答案,但这仍然让我感到困惑。

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

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

  1. 状态栏方向正确显示为横向(分布在屏幕上)。
  2. 选项卡栏视图正确显示为横向且选项卡居中。
  3. 所有视图对于所有方向的 shouldAutorotateToInterfaceOrientation 都返回 YES。

如果我在视图控制器的 viewWillAppear 中调用 [self interfaceOrientation] 或 [[UIApplication shareApplication] statusBarOrientation],则第三个选项卡的视图控制器报告 3(横向),但前两个视图控制器报告 1(纵向),即使状态栏清晰可见景观!

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

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

我缺少什么?

I have an iPad app that works correctly except for an odd issue during launch. I've read several questions & answers regarding orientation, but this still has me stumped.

The root view controller is a UITabBarController with 3 tabs. Two of the tabs are have custom view controllers (one based off of UIViewController, the other off of UITableViewController) and both suffer from this launch orientation problem. The third tab is a custom UITableViewController that's embedded in a UINavigationController.

OK, here's the problem. If I start the app in Portrait orientation, everything works great. If I start it in Landscape orientation, the 3rd tab works perfectly. However, the first 2 tabs come up in Portrait orientation, even though:

  1. The status bar orientation correctly shows as landscape (spread across the screen).
  2. The Tab Bar view correctly shows as landscape with the tabs centered.
  3. All views return YES for shouldAutorotateToInterfaceOrientation for all orientations.

If I call [self interfaceOrientation] or [[UIApplication sharedApplication] statusBarOrientation] in the view controller's viewWillAppear, then the 3rd tab's view controller reports 3 (landscape) but the first two view controllers report 1 (portrait) even though the status bar is clearly landscape!

If I rotate the iPad to portrait and back to landscape, then all 3 tabs' views rotate correctly (and the methods above return 3, as expected).

Also, if I tap on any other tab and then back on tab #1 or #2, then they will now rotate correctly, even without rotating the iPad itself!

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

萌辣 2024-09-06 15:06:36

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

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

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

You have to add the supportedDeviceOrientations to your "myApp.plist" .

Click on this list, add the key "Supported interface orientations" and add the supported interface orientations. This solved the problem for me.

For further informationen follow this link and go to the section "The Application Bundle": http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html

哭泣的笑容 2024-09-06 15:06:36

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

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

I finally found my answer: I just forgot this in my LoadingController.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}
野味少女 2024-09-06 15:06:36

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

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

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

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

I have found that the device orientation starts out with nothing. And should return YES for Unknown. This will allow it to orient the device with the correct launch orientation.

Here is the code I used to propigate this message up to the legacy messages.

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

notice I return YES if orientation == UIDeviceOrientationUnknown. This corrected my loading problem.

荒岛晴空 2024-09-06 15:06:36

解决方案是在 Info.plist 中添加一个关键的

UISupportedInterfaceOrientation

,其中包含一个字符串数组,指定启动时支持的界面方向,这些是

  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown code>
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight

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

The solution is to add a key

UISupportedInterfaceOrientation

to you Info.plist with an array of strings specifying the suppored interface orientations at launch time, these are

  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight

However, there is the follwing issue which may lead to confusion: At least with SDK 3.2 and iPad Simulator from XCode 3.2.4 I found that (at least some) Info.plist settings appeared to be cached and/or are not updated when installing the app. That is, adding the key above and installing and launching the app in the simulator had no effect. However, deleting the app from the simulator fixed the problem an the newly installed app behaved as specified.

内心旳酸楚 2024-09-06 15:06:36

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

[myViewController viewDidLoad];

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

In your app delegate's applicationDidFinishLaunchingWithOptions: method, after you add your view controller's view to the window, add the following:

[myViewController viewDidLoad];

If necessary, this will trigger a call to the shouldAutorotateToInterfaceOrientation: method.

情话已封尘 2024-09-06 15:06:36

试试这个

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

just try this

- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);<br>
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文