如何获得 iPhone 当前的方向? [英] How to get iPhones current orientation?
本文介绍了如何获得 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))
{
}
如果你想使用设备方向:
If you want the device orientation use:
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
这包括像 UIDeviceOrientationFaceUp
和 UIDeviceOrientationFaceDown
这篇关于如何获得 iPhone 当前的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文