为什么我的Cordova / PhoneGap iOS应用程序在设备旋转时旋转? [英] Why doesn't my Cordova/PhoneGap iOS app rotate when the device rotates?

查看:156
本文介绍了为什么我的Cordova / PhoneGap iOS应用程序在设备旋转时旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试风景只有应用程式,但我无法产生任何轮播。



以前是一个自动旋转设置在 PhoneGap.plist ,但在phonegap 1.8.0我可以找到它。它仍然存在吗?



还有什么可能是错误的,我的应用程序不旋转?



UPDATE



我知道网页只包含一个字词「test」。我将目标设备设置为iPad,并启用所有四个方向。仍然可能出错?



确实需要有一个特殊的html文档类型吗?我需要包括一些cordova-1.8.0.js吗?我找不到一个iOS(!?!)所以我测试它与Android版本。我读了API现在是一样的,所以我可以使用android的.js文件?

解决方案

PiTheNumber的答案看起来没问题修改Cordova生成的本机代码。



按照此关于Cordova的JIRA问题,以及在此博客中的整理解释,您还可以使用plist值或请在您的Javascript代码中定义一个window.shouldRotateToOrientation函数 ,它非常适合我。

  shouldRotateToOrientation = function(degrees){
return true;
}

这将启用当前页面的设备方向如果它是一个一页应用,因为大多数Cordova应用程序)。注意,你也可以决定根据旋转值以度为单位来启用它,甚至,为什么不启用它,只有在某些视图,或让用户在你的HTML应用程序中选择...很好,不是。 p>

对于记录,我不需要做任何事情来获得iOS 8 iPad手柄旋转,而iOS 6和iOS 7 iPhones将不会处理它默认情况下当前Cordova版本(4.2.0,cordova ios平台版本ios 3.7.0)。这是因为在Xcode上,每个设备类型(平板电脑/手机)可以授予不同的旋转设置。需要注意的是,Cordova会首先检查上面的JS函数是否存在,然后如果函数不存在或者不允许旋转,将使用Xcode循环设置。


I am trying to make a landscape only app, but I am not able to produce any rotation at all.

There used to be a autorotate setting in PhoneGap.plist but in phonegap 1.8.0 I can find it. Does it still exists?

What else could be wrong that my application is not rotating?

UPDATE

I know have webpage containing only one word "test". I set target device to iPad only and enabled all four orientations. What could still be wrong?

Do need to have a special html document type? Do I need to include some cordova-1.8.0.js? I could not find one for iOS (!?!) so i tested it with the android version. I read the API is now the same so can I use the android .js file?

解决方案

PiTheNumber's answer looks OK for those fine with modifying the Cordova-generated native code.

Following this JIRA issue on Cordova, and as neatly explained in this blog, you can also use plist values or define a window.shouldRotateToOrientation function in your Javascript code, which suits me very well.

window.shouldRotateToOrientation = function(degrees) {
 return true;
}

This would enable device orientation for the current page (so, for your whole app if it's a "one page app" as most Cordova apps are). Note you can also decide to enable it based on the rotation value in degrees, or even, why not, enable it only on certain views, or letting the user choose within your HTML app... Nice, isn't it.

For the record, I didn't need to do anything to get an iOS 8 iPad handle rotation, while both iOS 6 and iOS 7 iPhones wouldn't handle it by default in the current Cordova version (4.2.0, cordova ios platform version "ios 3.7.0"). That is because one can grant different rotation settings per "device type" (tablet / phone) on Xcode. The thing to note is that Cordova will first check the JS function above if it exists, and then if the function does not exist or it did not allow the rotation, the Xcode rotation setting will be used.

这篇关于为什么我的Cordova / PhoneGap iOS应用程序在设备旋转时旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆