I'm trying to use the new CoreMotion features, first of all, the ability to set a reference frame, but if I use DeviceMotionHandler, and the reference frame set to CMAttitudeReferenceFrameXTrueNorthZVertical, some of CMAttitudeReferenceFrameXArbitraryCorrectedZVertical is thrown. I run the application with iphone always in the same rotation as my table, and I test different initial rotation of the rotation, but the result is always the same.
motionManager = [[CMMotionManager alloc] init]; motionManager.showsDeviceMovementDisplay = YES; motionManager.deviceMotionUpdateInterval = 1.0/60.0; CMDeviceMotionHandler motionHandler = ^ (CMDeviceMotion *motion, NSError *error) { NSLog(@"%f %f %f", motion.attitude.pitch, motion.attitude.roll, motion.attitude.yaw); }; [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];
I found a solution to my problem, but I can not understand why the previous code does not work. I add only the CMAttitude * a variable to motionHandler.
- (void)viewDidLoad { [super viewDidLoad]; motionManager = [[CMMotionManager alloc] init]; motionManager.showsDeviceMovementDisplay = YES; motionManager.deviceMotionUpdateInterval = 1.0/60.0; CMDeviceMotionHandler motionHandler = ^ (CMDeviceMotion *motion, NSError *error) { CMAttitude *a = motionManager.deviceMotion.attitude; labelAngle.text = [NSString stringWithFormat:@"%f %f %f",a.pitch, a.roll,a.yaw]; labelAngle2.text = [NSString stringWithFormat:@"%f %f %f", motion.attitude.pitch, motion.attitude.roll, motion.attitude.yaw]; }; [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];}
Batti source share