Ability to lock orientation of device with JavaScript in PhoneGap/Cordova

落爺英雄遲暮 提交于 2019-12-06 15:45:25

问题


I'm looking for a way to programatically lock the orientation of a device in a PhoneGap/Cordova application using JavaScript for certain pages only.

I am aware that in can be locked globally in the config.xml file but I am searching for a solution that supports both iOS and Android whereby I can lock the orientation using a checkbox/radio control on a single page in my App.

I have found some possible Cordova plugins but they are all Android only.

I am willing to write a Cordova/PhoneGap plugin but I am not sure of the Objective-C and Java code required to lock the orientation using the various native API's.

Here is a great example of what I'm looking for (this is Android only but I need support for both iOS & Android): https://github.com/Hless/cordova-plugin-orientationchanger

Any advice would be greatly appreciated.

Many Thanks, XigenBen

*Remember this plugin only works in android and only if you put this: phonegap.js instead of cordova.js


回答1:


I stumbled across a plugin on the Cordova plugin registry that solves this exact issue, here's the URL for anyone interested: http://plugins.cordova.io/#/package/net.yoik.cordova.plugins.screenorientation

Can also be found on GitHub: https://github.com/yoik/cordova-yoik-screenorientation



来源:https://stackoverflow.com/questions/22843675/ability-to-lock-orientation-of-device-with-javascript-in-phonegap-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!