如何确定设备的角度?

cyn*_*joy 6 ios

我想我只是捕获起始UIAcceleration y值并将其与当前值进行比较然后"测量"但我并不确切地知道(1)这是正确的(2)数学应该是什么.

谢谢你的帮助.

更新:

这是我按照jrturton的建议使用的代码.

#import "ViewController.h"

@interface ViewController()
{
  CMMotionManager *motionManager;
}
@end

@implementation ViewController
@synthesize angleLabel;

- (void)startMotion
{
  if (motionManager == nil)
  {
    motionManager = [[CMMotionManager alloc] init];
  }
  motionManager = [[CMMotionManager alloc] init];
  [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
    angleLabel.text = [NSString stringWithFormat:@"%g", motion.attitude.pitch];
  }];
}

- (void) stopMotion
{
  if (motionManager)
  {
    [motionManager stopDeviceMotionUpdates];
  }

  motionManager = nil;
}

- (void)viewDidUnload {
    [self setAngleLabel:nil];
    [super viewDidUnload];
}
@end
Run Code Online (Sandbox Code Playgroud)

jrt*_*ton 4

比那更容易。使用 CMDeviceMotion 的attitude属性。请参阅此处的文档。