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
It's easier than that. Use CMDeviceMotion's attitude
property. See here for documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With