Я пробую новые функции CoreMotion, прежде всего, возможность установить опорный кадр, но если я использую DeviceMotionHandler и опорный кадр установлен в CMAttitudeReferenceFrameXTrueNorthZVertical, то результатом является часть CMAttitudeReferenceFrameXArbitraryCorrectedZVertical.
я запускаю приложение с iphone, всегда с одинаковым поворотом рыскания относительно моего стола, и я тестирую другой начальный поворот рыскания, но результат всегда одинаков.
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];
Я нашел решение своей проблемы, но не могу понять, почему предыдущий код не работает.
Я добавляю только переменную CMAttitude * a в 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];}