android - 在不旋转应用程序的情况下检测 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
});
使两者之间的旋转跳跃看起来很糟糕。
解决方案
你可以试试这个
您应该将此行添加到项目中的 config.xml 中。
<preference name="orientation" value="portrait" />
推荐阅读
- html - 一个 HTML 页面上的多个打印按钮,只打印某些部分?
- python - Django:尝试反转模型的 __str__() 函数
- swift - 将成员标记为私有导致 Argument Passed to Call That Takes No Arguments
- kubernetes - 无法解析同一 statefulset 中 pod 的主机名
- django - JsonResponse 数据未发送到模板
- windows - Windows 中的 .lib 文件是否像 Linux 中的 .a 文件?
- r - 如何检查列中的预定数字序列是否在r中一个接一个?
- javascript - Mathquill - 使用 latex() 解析器后删除了 \MathQuillMathField 命令
- python - 循环查找索引中的关键字,如果找到,则将该行附加到 df。如果没有找到,追加空df
- apache - Htaccess 将 URL 重定向到另一个并删除字符