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');
  }
});
相關文章
相關標籤/搜索