Cordova/Ionic - Set Portrait Only Mode for Mobiles and allow Orientation in Tablets

大城市里の小女人 提交于 2019-12-23 09:32:00

问题


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:


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


来源:https://stackoverflow.com/questions/34783909/cordova-ionic-set-portrait-only-mode-for-mobiles-and-allow-orientation-in-tabl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!