ionic 锁定方向 禁止横屏 orientation

安装插件 cordova-plugin-screen-orientation

ionic cordova plugin add cordova-plugin-screen-orientation  

添加配置 - config.xml

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

动态修改锁定方向

$scope.$on('$ionicView.beforeEnter', function() {
  if (typeof screen.orientation != 'undefined') {
    screen.orientation.unlock();
  }
});
$scope.$on('$ionicView.afterLeave', function() {
  if (typeof screen.orientation != 'undefined') {
    screen.orientation.lock('portrait');
  }
});
posted @ 2017-12-09 21:15  CooMark  阅读(961)  评论(0编辑  收藏  举报