Question

How to find out if the UIDeviceOrientationFaceUp is landscape FaceUp or Portrait FaceUp?

Can any one tell me?

Was it helpful?

Solution

It's not possible, because the accelerometer can't detect rotation around the z axis. On an iPhone 4, you could perhaps use the gyroscope for this (using CoreMotion), but UIDevice doesn't have an API for this. You would then also have to define what the starting position is, because you can't detect in which direction the user is from the device's point of view.

OTHER TIPS

UIDeviceOrientation will only tell you the orientation of the physical device. You need to use methods that use UIInterfaceOrientation (from UIApplication) to make decisions depending on whether the screen is in portrait and landscape mode.

You can use UIInterfaceOrientationIsLandscape() and UIInterfaceOrientationIsPortrait() with a UIInterfaceOrientation too.

I realise this is an old question now, but looking at the answers everyone is being overly pedantic. In case anyone else stumbles across this:

The answer to your problem is for you to keep a secondary variable which is any of your accepted orientations.

When the device orientation notification comes in, simply look at the incoming orientation and see if its an acceptable one, (portrait/landscape NOT faceup/facedown) then update your secondary variable, and finally trigger a ui/app refresh from there using your secondary variable as the orientation source.

This will have the effect of locking the orientation to the "last known good" orientation.

UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown are orientations for when the device is laying flat (like on a table). Portrait and Landscape don't make sense in this cases.

There is no way you can find out from orientation . I have found a workaround.

CGRect screenBounds = [[UIScreen mainScreen]bounds];

if(screenBounds.size.width > screenBounds.size.height)
{
    // This means FaceUP/Down is in Landscape
}
else
{
    // This means FaceUp/Down is in Portrait
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top