有没有一种特殊的方法来获取iPhone的方向?我不需要度数或弧度,我希望它返回一个UIInterfaceOrientation对象。我只需要一个如果 - 其他建设像如何获取iPhone目前的方向?
if(currentOrientation==UIInterfaceOrientationPortrait ||currentOrientation==UIInterfaceOrientationPortraitUpsideDown) {
//Code
}
if (currentOrientation==UIInterfaceOrientationLandscapeRight ||currentOrientation==UIInterfaceOrientationLandscapeLeft) {
//Code
}
在此先感谢!
是的,它的工作!比你非常! – Knodel 2010-03-26 08:14:43
这在技术上是错误的,你从你的方法调用中获得一个UIDeviceOrientation并将其存储在一个UIInterfaceOrientation中。 UIInterfaceOrientation是4中的一个,它代表了你的界面看起来像什么。 UIDeviceOrientation是6之一(包括平放和平躺倒置),并告诉你设备的方向,而不一定是你的界面的样子。您的界面可以处于肖像模式,但如果设备坐在桌子上,它将返回UIDeviceOrientationFaceUp。 – 2011-04-26 02:36:18
@CoryImdieke:感谢您更新设备和界面方向之间的差异。 UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];是正确的API – Senthil 2011-12-22 12:08:51