检测到iPhone已使用phonegap旋转(加速度计)

时间:2010-07-21 15:24:54

标签: iphone accelerometer cordova

有人可以请我找到正确的方向,找出如何识别iPhone已经旋转,请使用PhoneGap吗?

谢谢! 下进行。

1 个答案:

答案 0 :(得分:0)

如果您不熟悉phonegap,请查看Jonathan Stark's great introduction

如果您已熟悉phonegap并且只需要代码段,请查看错误报告here。正如您所看到的,在当前版本中看来watchOrientation存在一些问题,但Shazron提供了我在此处复制的解决方法:

function onDeviceReady()
{
    // do your thing!
    document.addEventListener("orientationChanged", UpdateOrientation);

}

function UpdateOrientation(e)
    {
        switch(e.orientation)
        {
            case 0: // portrait
            case 180: // portrait
        // do your thing here
                break;
            case -90: // landscape
            case 90: // landscape
        // do your thing here
                break;
        }    
    }