开发者

detect that iPhone has been rotated using phonegap ( accelerometer)

开发者 https://www.devze.com 2023-01-08 01:36 出处:网络
Could someone please lead 开发者_开发知识库me in the right direction to finding out how to recognize that the iPhone has been rotated, using PhoneGap please?

Could someone please lead 开发者_开发知识库me in the right direction to finding out how to recognize that the iPhone has been rotated, using PhoneGap please?

Thanks! C.


If you are not familiar with phonegap, check out Jonathan Stark's great introduction.

If you are already familiar with phonegap and just need a code snippet, then take a look at the bug report here. As you can see, it appears there are some problems with watchOrientation in the current release but Shazron provides a workaround which I've copied here:

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;
        }    
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号