cordova 强制竖屏

orentation的默认值是default

可使用的值有:default, landscape (横屏), portait (竖屏)

orentation可以将设备锁定方向,不受设备旋转影响。


方案一:

1、添加插件

cordova plugin add net.yoik.cordova.plugins.screenorientation

2、添加屏幕配置 (Config.xml文件里面添加)

<preference name="orientation" value="portrait" />

3、在Index.html 界面 添加JS 屏幕监听事件

<script> 
  document.addEventListener("deviceready", onDeviceReady, false); 
  function onDeviceReady(){
    var so = cordova.plugins.screenorientation; 
    so.setOrientation(so.Orientation.LANDSCAPE); 
  } 
</script>

方案二:

1、添加插件

cordova plugin add cordova-plugin-screen-orientation

2、添加屏幕配置 (Config.xml文件里面添加)

<preference name="orientation" value="portrait" />

.

原文地址:https://www.cnblogs.com/crazycode2/p/6337888.html