使用来自iPhone的cattitude *信息,您可以告诉pitch。如果iPhone是垂直的,它是90度。如果是平的,就是0度。但我有一个应用程序需要知道iPhone是朝上还是朝下/向前还是向后。知道这能不能做到吗?
> * CMAttitude *attitude;
> CMDeviceMotion *motion = motionManager.deviceMotion;
> attitude = motion.attitude;
您是否尝试过使用UIDevice类检查设备方向?
编辑:首先添加一个观察者来监视方向变化:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
在回调中,获取当前设备的方向
- (void)orientationDidChange:(NSNotification*)notification
{
/// check current orientation
switch ([[UIDevice currentDevice] orientation])
{
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationPortraitUpsideDown:
break;
case UIDeviceOrientationLandscapeLeft:
break;
case UIDeviceOrientationLandscapeRight:
break;
case UIDeviceOrientationFaceUp:
break;
case UIDeviceOrientationFaceDown:
break;
default: /// UIDeviceOrientationUnknown
break;
}
}
当设备改变方向时,它会通知你。
支持的方向可以在这里找到:https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html