开发者

UIDevice Orientation

How to find out if the UIDeviceOrientati开发者_StackOverflowonFaceUp is landscape FaceUp or Portrait FaceUp?

Can any one tell me?


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.


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.


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜