如何获得iPhone的当前方向?

如何获得iPhone的当前方向?

问题描述:

是否有一种特殊的方法来确定iPhone的方向?我不需要度或弧度,我希望它返回一个UIInterfaceOrientation对象.我只需要

Is there a special method to get iPhones orientation? I don't need it in degrees or radians, I want it to return an UIInterfaceOrientation object. I just need it for an if-else construction like

if(currentOrientation==UIInterfaceOrientationPortrait ||currentOrientation==UIInterfaceOrientationPortraitUpsideDown) {
//Code
}  
if (currentOrientation==UIInterfaceOrientationLandscapeRight ||currentOrientation==UIInterfaceOrientationLandscapeLeft ) {
//Code
}

提前谢谢!

这很可能是您想要的:

UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

然后您可以使用系统宏,例如:

You can then use system macros like:

if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
{

}

如果要使用设备方向:

UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];

这包括UIDeviceOrientationFaceUpUIDeviceOrientationFaceDown