【问题标题】:Allow screen rotation on tablets, but not phones in Ionic 4允许在平板电脑上旋转屏幕,但在 Ionic 4 中不允许手机上的屏幕旋转
【发布时间】:2019-08-17 03:45:00
【问题描述】:

我发现这个线程会为每台设备锁定它How to restrict app to portrait mode only in ionic for all platforms?,但我想做的是允许平板电脑上的屏幕旋转,而不是手机。

我希望这是我可以在 config.xml 中设置的东西,但我想我需要更多类似 https://ionicframework.com/docs/native/screen-orientation/ 的东西,并以编程方式完成,除非我遗漏了什么。有什么想法吗?

【问题讨论】:

    标签: ionic-framework ionic4


    【解决方案1】:

    您可以使用import { Platform} from 'ionic-angular'; 检查设备,使用import { ScreenOrientation } from '@ionic-native/screen-orientation'; 旋转屏幕。

    constructor(private navCtrl: NavController, private plt: Platform, private screen: ScreenOrientation) {
        if (this.plt.is('tablet')) {
          if (this.screen.type === 'portrait-primary') {
            this.screen.lock(this.screen.ORIENTATIONS.LANDSCAPE);
          }
        }
      }
    

    此代码检查设备是否为平板电脑并检查屏幕是否为纵向,然后它将自动将您的屏幕旋转到横向模式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      相关资源
      最近更新 更多