我在下面找到了这个方向测试代码,寻找JQTouch参考资料.这在移动Safari上的iOS模拟器中正常工作,但在Phonegap中无法正确处理.我的项目遇到了与杀死此测试页面相同的问题.有没有办法在Phonegap中使用JavaScript来感知方向变化?
window.onorientationchange = function() {
/*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
left, or landscape mode with the screen turned to the right. */
var orientation = window.orientation;
switch (orientation) {
case 0:
/* If in portrait mode, sets the body's class attribute to portrait. Consequently, all style definitions matching the body[class="portrait"] declaration
in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or …Run Code Online (Sandbox Code Playgroud) 我正在为这个orientationchange事件添加一个监听器:
window.addEventListener('orientationchange', function () {
console.log(window.innerHeight);
});
Run Code Online (Sandbox Code Playgroud)
我需要获得文件的高度orientationchange.但是,事件在旋转完成之前触发.因此,记录的高度反映了实际方向变化之前的状态.
如何在完成方向更改后注册允许我捕获元素尺寸的事件?
我想检测方向变化,检测我正在以纵向模式或横向模式查看我的应用程序。那么有没有像方向变化这样的事件,我可以在我的组件中的主机侦听器中传递来检测方向变化?
PS - 有些人说这是重复的问题。我不想要普通的 java 脚本方式,我想要角度方式来检测方向变化。