6

I'm thinking that I just capture the starting UIAcceleration y value and compare it to the current value and then 'measure' but I don't exactly know if (1) that is right (2) what that math should be.

Thanks for any help.

Update:

Here is the code I used as suggested by 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
cynicaljoy
  • 2,047
  • 1
  • 18
  • 25

1 Answers1

4

It's easier than that. Use CMDeviceMotion's attitude property. See here for documentation.

jrturton
  • 118,105
  • 32
  • 252
  • 268