繁体   English   中英

未检测到iPad的启动方向

[英]iPad launch orientation not detected

我有一个iPad应用程序,除了启动过程中出现了奇怪的问题之外,都可以正常运行。 我已经阅读了有关定向的一些问题和答案,但这仍然让我感到困惑。

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

好,这是问题所在。 如果我以纵向方向启动应用程序,则一切正常。 如果我以“横向”启动,则第三个选项卡可以完美运行。 但是,前两个选项卡以纵向显示,即使:

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

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

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

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

我想念什么?

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

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

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

我发现设备方向一无所有。 并且应为“未知”返回“是”。 这将使其能够以正确的发射方向定向设备。

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

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

注意,如果取向== UIDeviceOrientationUnknown,我将返回YES。 这解决了我的加载问题。

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

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

试试这个

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

解决方法是添加一个密钥

UISupportedInterfaceOrientation

给您Info.plist的字符串数组,这些字符串指定了启动时支持的界面方向,这些是

  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight

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

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

[myViewController viewDidLoad];

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM