IOS gyro to make a virtual horizon

I want to enable a virtual horizon for my application using a gyroscope like this

I found a lot of documentation on the gyroscope, and I think I use digging, but I don’t know how to calibrate using gravity.

Can someone help me?

thanks.

+6
source share
1 answer

I solved the problem with this:

- (void)updateImage: (NSNumber *)rotNum { self.image.transform = CGAffineTransformMakeRotation([rotNum floatValue]); } // call the above function to rotate the image in reference to the horizon [motionManager startDeviceMotionUpdatesToQueue: gyroQueue withHandler: ^(CMDeviceMotion *motion, NSError *error) { [self performSelectorOnMainThread: @selector(updateImage:) withObject: [NSNumber numberWithDouble: atan2(motion.gravity.x, motion.gravity.y)-M_PI] waitUntilDone: NO]; }]; 
+7
source

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


All Articles