离子:ScreenOrientation to Portrait

时间:2015-10-23 14:34:00

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

我正在开发一个Ionic-App,我想将Screen Orientation设置为Portrait。 我知道我可以用它来设置它:

<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();
    }

1 个答案:

答案 0 :(得分:0)

我已经为我的项目使用了 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