Cordova 在 Orientation="portrait" 时检测屏幕方向
Cordova detect screen orientation when Orientation="portrait"
我希望我的应用程序始终纵向显示,所以在 config.xml 文件中我有这一行。
<preference name="Orientation" value="portrait"/>
效果很好。
问题是之后我无法检测到屏幕方向。
我试过
function doOnOrientationChange() {
console.log(window.orientation);
}
window.addEventListener('orientationchange', doOnOrientationChange);
doOnOrientationChange();
当我的 phone 处于纵向时,此代码向我显示 0
,而当它处于倒置状态时 180
,但在横向时什么也没有(不是 90
也不是 -90
).
我看到这个插件 https://github.com/gbenvenuti/cordova-plugin-screen-orientation 似乎有很多人在使用,但我无法在我的 iPhone 6S (iOS9) 上使用它,看完问题,好像不止我一个人...
现在我不知道该去哪里,所以非常感谢任何形式的帮助!
问题是那些函数或插件正在返回屏幕方向,而不是设备方向。这就是为什么你只得到0或180的原因。可能你需要使用这个插件,它读取设备罗盘,这样你就可以得到你想要的
https://github.com/apache/cordova-plugin-device-orientation
编码愉快!
我还没有测试过,但我刚刚遇到了 Screen Orientation 插件(来自 Cordova),这正是我要找的。
谢谢大家的帮助!
我希望我的应用程序始终纵向显示,所以在 config.xml 文件中我有这一行。
<preference name="Orientation" value="portrait"/>
效果很好。
问题是之后我无法检测到屏幕方向。
我试过
function doOnOrientationChange() {
console.log(window.orientation);
}
window.addEventListener('orientationchange', doOnOrientationChange);
doOnOrientationChange();
当我的 phone 处于纵向时,此代码向我显示 0
,而当它处于倒置状态时 180
,但在横向时什么也没有(不是 90
也不是 -90
).
我看到这个插件 https://github.com/gbenvenuti/cordova-plugin-screen-orientation 似乎有很多人在使用,但我无法在我的 iPhone 6S (iOS9) 上使用它,看完问题,好像不止我一个人...
现在我不知道该去哪里,所以非常感谢任何形式的帮助!
问题是那些函数或插件正在返回屏幕方向,而不是设备方向。这就是为什么你只得到0或180的原因。可能你需要使用这个插件,它读取设备罗盘,这样你就可以得到你想要的
https://github.com/apache/cordova-plugin-device-orientation
编码愉快!
我还没有测试过,但我刚刚遇到了 Screen Orientation 插件(来自 Cordova),这正是我要找的。
谢谢大家的帮助!