如何在正确的横向方向上启动应用程序,而无需在启动时旋转180°?

时间:2014-03-29 10:49:02

标签: ios ios7

我面临着一个仅限横向应用的奇怪问题。它可以向左或向右旋转,但是当应用程序启动时,它会旋转180度而不是以正确的方向启动。

我做了我能在StackOverflow和Google上找到的所有内容。信息plist包含:

enter image description here enter image description here

经过测试:iOS 7.1完全忽略了plist中的初始启动方向设置。我尝试了左右两种,然后删除了来自info plist的密钥。没有效果。应用程序始终使用左侧的主页按钮启动横向,忽略此设置。 enter image description here

重试时,我删除了应用并清理了构建。

在App Delegate中,我有这个:

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

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotate {
    return YES;
}

在根视图控制器中:

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

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotate {
    return YES;
}

像Tiny Wings这样的一些风景应用程序以正确的方向启动,所以我知道我的项目有问题。让这个工作的秘诀是什么?

4 个答案:

答案 0 :(得分:4)

首先,您不需要AppDelegate中的三种方法,因为它们仅适用于控制器,并且无论如何都不会被调用。

您可以实施application:supportedInterfaceOrientationsForWindow:(iOS 6+),但它表示Info.plist中的正确密钥不需要{<1}}:

  

<强>讨论

     

此方法返回支持的界面方向的总集   通过应用程序。确定是否旋转特定视图时   控制器,此方法返回的方向相交   具有由根视图控制器或最顶层支持的方向   呈现视图控制器。应用和视图控制器必须同意   在允许轮换之前。

     

如果您没有实现此方法,应用程序将使用中的值   应用程序的Info.plist的UIInterfaceOrientation键作为默认值   界面方向。

但如果您的问题出现在iOS 6+上,我会尝试一下,因为它可能是Apple的错误。

此外,您可以在控制器方法中返回所有方向以保持简单。


总之:

  • 删除您从AppDelegate发布的方法,不会被调用。
  • 返回控制器中的所有方向。
  • 然后使用Info.plist(任何iOS版本)控制您的首选方向。

可选,如果问题仍然存在:

  • 尝试在application:supportedInterfaceOrientationsForWindow:(仅限iOS 6+)中实施AppDelegate,这通常不需要。

答案 1 :(得分:3)

iOS始终将应用程序启动到相同的界面方向(我相信应用程序宣布的第一个应用程序)然后在启动后旋转。这是预期的行为,因为它简化了开发的某些方面。

但是,我相信这个问题的答案是您正在寻找的解决方案: iOS: Initial interface orientation[UIInterfaceOrientation] being ignored in plist

答案 2 :(得分:1)

到目前为止,我得到了你的问题,这可能会帮到你。您可以在一般设置中在设备方向上简单地勾选横向(右/左)模式。 Tick orientation which you want

无需改变plist或任何东西。这对我有用,因为我创建了一个横向模式的游戏,所以它只是在横向模式下打开而没有旋转效果。

答案 3 :(得分:0)

您需要更改Supported interface orientationsSupported interface orientations (iPad)的值顺序。因此,Landscape (right home button)应该先行,Landscape (left home button)应该在这些列表中排在第二位。

此外,您可以安全地从Initial interface orientation删除.plist。这三种方法与AppDelegateRootViewController中的界面方向处理有关。

相关问题