Cordova/Ionic - Set Portrait Only Mode for Mobiles

2019-06-20 08:14发布

How do we set Mobile phones to Portrait only and allow tablets to switch between portrait and landscape?

I am using Ionic/Cordova.

Currently I have configured to set the app to be in portrait mode in config.xml using the following property

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

1条回答
做自己的国王
2楼-- · 2019-06-20 09:05

You could use isTablet plugin in conjunction with screen orientation plugin, something like:

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.isTablet){
        screen.unlockOrientation();
    }else{
        screen.lockOrientation('portrait');
    } 
  });
})
查看更多
登录 后发表回答