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

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

问题描述

我正在尝试制作风景只有应用程序,但我根本无法产生任何旋转.

过去在 PhoneGap.plist 中有一个 autorotate 设置,但在 phonegap 1.8.0 中我可以找到它.还存在吗?

我的应用程序没有轮换还有什么问题?

更新

我知道有一个网页只包含一个词测试".我将目标设备设置为仅 iPad 并启用所有四个方向.可能还有什么问题?

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

解决方案

PiTheNumber 的答案对于那些可以修改 Cordova 生成的本机代码的人来说看起来不错.

在 Cordova 上关注 这个 JIRA 问题,并按照在本博客中,您还可以使用 plist 值或定义一个 window.shouldRotateToOrientation 函数Javascript 代码,非常适合我.

window.shouldRotateToOrientation = function(degrees) {返回真;}

这将为当前页面启用设备方向(因此,对于您的整个应用程序,如果它是大多数 Cordova 应用程序的单页应用程序").请注意,您还可以根据以度为单位的旋转值来决定启用它,甚至为什么不启用它,仅在某些视图上启用它,或者让用户在您的 HTML 应用程序中选择...很好,不是吗.

为了记录,我不需要做任何事情来获得 iOS 8 iPad 手柄旋转,而 iOS 6 和 iOS 7 iPhone 在当前的 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天全站免登陆