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

iam*_*mer 12 ios ios7

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

我在StackOverflow和Google上做了我能找到的一切.信息plist包含:

在此输入图像描述 在此输入图像描述

经过测试:iOS 7.1完全忽略了plist中的初始启动方向设置.我左右尝试,然后从信息plist中删除了密钥.没有效果.应用程序始终使用左侧的主页按钮启动横向,忽略此设置. 在此输入图像描述

重试时,我删除应用程序并清理构建.

在App Delegate中,我有:

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

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

- (BOOL)shouldAutorotate {
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在根视图控制器中:

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

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

- (BOOL)shouldAutorotate {
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

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

Riv*_*era 4

首先,您不需要您的三个方法,AppDelegate因为它们是用于控制器的,无论如何都不会被调用。

\n\n

您可以实现application:supportedInterfaceOrientationsForWindow:(iOS 6+),尽管它说不需要使用正确的键Info.plist

\n\n
\n

讨论

\n\n

此方法返回应用程序支持的界面方向的总集。当确定是否旋转特定视图控制器时,此方法返回的方向与根视图控制器或最顶层呈现的视图控制器支持的方向相交。应用程序和视图控制器必须在允许旋转之前\n达成一致。

\n\n

如果您不实现此方法,应用程序将使用 app\xe2\x80\x99s Info.plist 的 UIInterfaceOrientation 键中的值作为默认界面方向。

\n
\n\n

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

\n\n

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

\n\n
\n\n

总共:

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

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

\n\n
    \n
  • 尝试application:supportedInterfaceOrientationsForWindow:在您的AppDelegate(仅限 iOS 6+)中实现,这通常是不需要的。
  • \n
\n


归档时间:

查看次数:

2869 次

最近记录:

11 年,5 月 前