当我使用 iPhone 在我的应用程序中旋转屏幕时,它始终保持纵向并且没有任何变化。但是它适用于 iPad。我可以旋转它并改变方向。
如何让我的应用程序在我转动 iPhone 时改变屏幕方向?
在 config.xml 我有:
<preference name="Orientation" value="default" />
我能找到的唯一解决方案是在 cordova 代码中更改 MainViewController.m 中的方法 shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
-- return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
++ return true;
}
但这对我来说似乎是一个丑陋的解决方案,我真的很想找到这样做的正常方法。
理想情况下,除了 portraitUpsideDown 之外,iPad 和 iPhone 的所有方向都很好,但我不知道我是否可以梦想它。
有没有其他人对 iPhone 和 cordova 有类似的问题?我已经在谷歌上搜索了好几天,除了 cordova 代码中的这个 hack 之外找不到任何东西。
最佳答案
在广泛搜索解决方案之后,不幸的是我得出的结论是这是一个 Cordova 问题。
<preference name="Orientation" value="default" />
代码实际上应该更改 iOS 配置文件 (/platform/ios/~app_name~/~app_name~.plist) 中的平台 UISupportedInterfaceOrientations 键以包含以下值:
- "UIInterfaceOrientationLandscapeLeft";
- "UIInterfaceOrientationLandscapeRight";
- "UIInterfaceOrientationPortrait";和(我认为)
- “UIInterfaceOrientationPortraitUpsideDown”
不幸的是,更改 config.xml 文件不会更改 plist 文件,这很烦人。希望这会很快得到解决,从网上找到的帖子来看,人们浪费了很多时间寻找解决方案。
我找到的最简单的解决方案是手动更改 ~app_name~.plist 文件以包含上述值。我一直在 Xcode 中做这件事,这很容易做到。
希望这对您有所帮助。如果有更好的解决方案或 Cordova 修复此疏忽,请告诉我。
关于ios - iPhone 屏幕方向在 cordova 3.5.0 中没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25054554/