How to determine the angle of the device?

I think that I just fix the initial value of UIAcceleration y and compare it with the current value and then โ€œmeasureโ€, but I donโ€™t know if (1) (2) is correct what this mathematics should be.

Thanks for any help.

Update:

Here is the code I used as jrturton suggested.

#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 
+6
source share
1 answer

It is easier than that. Use the CMDeviceMotion attitude property. See here for documentation.

+4
source

Source: https://habr.com/ru/post/904818/


All Articles