首页 > 解决方案 > 在不旋转应用程序的情况下检测 Ionic 4 中的设备旋转/方向

问题描述

是否可以在不实际旋转整个应用程序的情况下检测 Ionic 4 应用程序中的旋转/方向变化?

我正在使用这个: https ://ionicframework.com/docs/native/screen-orientation

我想在设备旋转时输入一些回调,不一定要旋转整个应用程序。如果我锁定方向,我会丢失 screenOrientation.onChange() 发出的信息。如果我解锁旋转,我的 screenOrientation.onChange() 会发出,但整个应用程序 webview 也会旋转。

尝试这样的事情:

this.screenOrientation.unlock();
this.screenOrientation.onChange().subscribe(ev => {
        this.screenOrientation.lock(
          this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY
        );
        // Do other stuff
});

使两者之间的旋转跳跃看起来很糟糕。

标签: androidiosangularionic-framework

解决方案


你可以试试这个

您应该将此行添加到项目中的 config.xml 中。

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

推荐阅读