我正面临一个奇怪的问题,只有一个横向应用程序.它可以向左或向右旋转,但是当应用程序启动时,它会旋转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这样的一些风景应用程序以正确的方向启动,所以我知道我的项目有问题.让这个工作的秘诀是什么?
首先,您不需要您的三个方法,AppDelegate
因为它们是用于控制器的,无论如何都不会被调用。
您可以实现application:supportedInterfaceOrientationsForWindow:
(iOS 6+),尽管它说不需要使用正确的键Info.plist
:
\n\n\n讨论
\n\n此方法返回应用程序支持的界面方向的总集。当确定是否旋转特定视图控制器时,此方法返回的方向与根视图控制器或最顶层呈现的视图控制器支持的方向相交。应用程序和视图控制器必须在允许旋转之前\n达成一致。
\n\n如果您不实现此方法,应用程序将使用 app\xe2\x80\x99s Info.plist 的 UIInterfaceOrientation 键中的值作为默认界面方向。
\n
但如果你的问题是在 iOS 6+ 上,我会尝试一下,因为这可能是 Apple 的错误。
\n\n此外,您也可以只返回控制器方法中的所有方向以保持简单。
\n\n总共:
\n\nAppDelegate
,它们将不会被调用。Info.plist
然后用您的(任何 iOS 版本)控制您的首选方向。如果问题仍然存在,可选:
\n\napplication:supportedInterfaceOrientationsForWindow:
在您的AppDelegate
(仅限 iOS 6+)中实现,这通常是不需要的。 归档时间: |
|
查看次数: |
2869 次 |
最近记录: |