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