views:

112

answers:

1

Hi,

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.

A: 

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