【问题标题】:Ionic: ScreenOrientation to Portrait离子:屏幕方向到纵向
【发布时间】:2015-11-30 20:43:46
【问题描述】:

我正在开发一个 Ionic-App,我想将屏幕方向设置为纵向。 我知道我可以这样设置:

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

但这不起作用,

我找到了一个名为 screen-orientation-plugin 的 cordova 插件,但这也不起作用。您对此有其他解决方案吗?或者谁能​​解释一下这两种方法是如何正常工作的?

.config(function($ionicConfigProvider, $stateProvider, $urlRouterProvider, $compileProvider) {
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {

      $scope.changeOriantationPortrait = function() {
          screen.lockOrientation('portrait');
      }
      changeOriantationPortrait();
    }

【问题讨论】:

  • 你是说方向默认设置为横向?
  • @MegaAppBear 不,我的意思是我不能将方向冻结为纵向
  • 科尔多瓦版本?您测试的操作系统?
  • cordova 5.3.3 和 iOS 9

标签: ios cordova ionic-framework ionic cordova-plugins


【解决方案1】:

我在我的项目中使用了 this 插件,效果很好

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

控制器

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    $scope.changeOriantationLandspace = function() {
        screen.lockOrientation('landscape');
    }

    $scope.changeOriantationPortrait = function() {
        screen.lockOrientation('portrait');
    }
}

HTML

<button class="button button-full button-positive " ng-click="changeOriantationLandspace()">Change To Landspace Mode</button>
<br/>
<button class="button button-full button-positive " ng-click="changeOriantationPortrait ()">Change To Portrait Mode</button>

Reference

【讨论】:

  • 谢谢 Mushin,是的,我也试过了,但是当我将它实现到我的代码中时,整个应用程序不起作用,并且在控制台中他说屏幕不是函数:/
  • 问题是,我没有得到任何错误。设备就绪侦听器不会被触发,但是当我将方法注释掉时,设备就绪事件会被触发。
  • 在问题中添加了它
  • 你能帮我做一个小演示吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-18
  • 2015-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多