【问题标题】:iPad orientation behaviour inconsistent - changes on each launch?iPad 方向行为不一致 - 每次启动都会发生变化?
【发布时间】:2011-10-19 01:02:16
【问题描述】:

我有一个非常奇怪的问题,我至今无法诊断。

在我的 iOS 应用程序(它是一个通用二进制文件)中,当我在 iPad 4.3 上运行时,启动时的方向不一致。

应用委托将启动画面 (UIViewController) 添加到主窗口,然后将其移除并添加应用的主视图。问题在于这个主视图 - 大约一半的时间,它以横向正确加载,另一半以纵向加载视图(尽管状态栏和键盘都正确地以横向加载)。

当我不对代码或模拟器/设备方向进行任何更改时,为什么启动时的方向会发生变化,我有点茫然。

我在 Info.plist 中将 UIInterfaceOrientationLandscapeLeft 和 UIInterfaceOrientationLandscapeRight 设置为 iPad 唯一支持的方向,并且每个视图控制器都使用以下内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // The device is an iPad running iPhone 3.2 or later.
        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            return YES;
        }

    } else {
        // The device is an iPhone or iPod touch.
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            return YES;
        }

    }

    return NO;
}

谁能帮我解决这个问题?

干杯,

奥利

【问题讨论】:

  • 好的,我解决了这个问题。原来 iPad 不喜欢我添加和删除视图的方式。我将启动视图添加为窗口的 rootViewController,然后将其删除并将我的主视图添加为 rootViewController。我通过添加一个导航控制器(navigationBarHidden = YES)作为窗口的 rootViewController,然后将我的初始屏幕添加为导航控制器的根来解决了这个问题。然后我只需将主视图推送到堆栈上。仍然不确定为什么 iPad 不喜欢我原来的方法,但这种解决方法对我有用。

标签: ios ipad orientation


【解决方案1】:

如果状态栏和键盘始终处于横向状态,则问题不应出在 shouldAuto... 方法中。它可能在 viewDidLoad 中。另外,请尝试以下操作:在 project-info.plist 中,将“初始界面方向”设置为横向左/右,“清理”项目并运行。

【讨论】:

  • 因为它是一个通用二进制文件,并且对于 iPad/iPhone 的初始界面方向没有单独的选项,这将破坏 iPhone 上的 UI(该应用程序在 iPhone 上是纵向的)。即便如此,作为测试,我尝试了它并没有解决问题。我可以在 viewDidLoad 中做什么来解决这个问题?
猜你喜欢
  • 2012-05-18
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 2021-02-11
  • 2018-07-12
  • 1970-01-01
  • 1970-01-01
  • 2016-05-24
相关资源
最近更新 更多