为什么设备旋转时我的Cordova / PhoneGap iOS应用程序不能旋转?
我正在尝试制作一个仅适用于横向的应用程序 ,但是我根本无法进行任何旋转。
PhoneGap.plist
中曾经有一个autorotate
设置,但是在1.8.0版本的手机上,我可以find它。 它还存在吗?
还有什么可能是错误的,我的应用程序不旋转?
UPDATE
我知道有网页只包含一个单词“testing”。 我只将目标设备设置为iPad,并启用所有四个方向。 还有什么可能是错的?
需要有一个特殊的HTML文档types? 我需要包含一些cordova-1.8.0.js吗? 我无法find一个iOS(!?!),所以我testing了与Android版本。 我读的API现在是一样的,所以我可以使用android .js文件?
PiTheNumber的答案看起来不错,修改Cordova生成的本机代码。
在Cordova的这个JIRA问题上,并且在这个博客中整齐的解释,你也可以使用plist值或者在你的Javascript代码中定义一个window.shouldRotateToOrientation函数,这非常适合我。
window.shouldRotateToOrientation = function(degrees) { return true; }
这将使设备的方向为当前页面(所以,如果您的整个应用程序是大多数cordova应用程序是“单页应用程序”)。 请注意,您也可以根据旋转值(以度为单位)启用它,甚至为什么不启用它,只能在某些视图中启用它,或者让用户在您的HTML应用程序中select…好的,不是吗?
为了logging,我不需要做任何事情来获得iOS 8的iPad手柄旋转,而iOS 6和iOS 7的iPhone手机在目前的cordova版本(4.2.0,cordova ios平台版本“ios 3.7.0”)。 这是因为可以在Xcode上为“设备types”(平板电脑/手机)授予不同的旋转设置。 需要注意的是,Cordova首先会检查JS函数是否存在,如果函数不存在或者不允许旋转,则使用Xcode旋转设置。
我尝试了上面的JavaScript解决scheme,并没有喜悦在Visual Studio 2015我更改config.xml
<preference name="orientation" value="all" />
采取从cordova5 build命令是删除iOS设备的方向设置
我不需要JavaScript只是configuration设置
在Classes/MainViewController.m
返回true:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations //return (interfaceOrientation == UIInterfaceOrientationPortrait); return true; }
对于iOS> = 6
- (BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; }
资源
您可以添加UISupportedInterfaceOrientations
platroms / IOS / {项目名} / {项目名-info.plist中
添加这些行:
对于iPhone:
<key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeRight</string> </array>
对于Ipad:
<key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeRight</string> </array>