如何获取iPhone当前的方向?
我浏览了这个网站,发现了以下两种方法。
- [UIApplication共享应用程序].statusBarOrientation;
- [[UIDevice currentDevice]方向];
哪一种是获取当前方向的正确方法?
我在模拟器4.1下尝试了两种方法,但是两种方法都存在一些问题。
注册您的类以侦听 UIDeviceOrientationDidChangeNotification,然后相应地处理设备方向。
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(deviceRotated:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
并正确处理设备的方向:
- (void)deviceRotated: (id) sender{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationFaceUp ||
orientation == UIDeviceOrientationFaceDown)
{
//Device rotated up/down
}
if (orientation == UIDeviceOrientationPortraitUpsideDown)
{
}
else if (orientation == UIDeviceOrientationLandscapeLeft)
{
}
else if (orientation == UIDeviceOrientationLandscapeRight)
{
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)