安装插件 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');
}
});
05-08 08:42