iphone - 带有引用框架的 CoreMotion iOS 5 态度不起作用

标签 iphone objective-c ios5 core-motion

我正在尝试 CoreMotion 的新功能,最重要的是设置引用系的可能性,但如果我使用 DeviceMotionHandler 并将引用系设置为 CMAttitudeReferenceFrameXTrueNorthZVertical,则输出是 CMAttitudeReferenceFrameXArbitraryCorrectedZVertical 的一部分。 我用 iphone 启动应用程序时总是以相同的偏航旋转尊重我的 table ,我测试了不同的初始偏航旋转,但结果总是一样的。

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];

我找到了我的问题的解决方案,但我不明白为什么以前的代码不起作用。 我在 motionHandler 中只添加了一个 CMAttitude 变量 *a。

- (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];}

最佳答案

我认为这是因为.. 如果您先定义处理程序,则运动对象的态度属性已经设置为默认值。稍后在您自己的代码中,此态度属性变为只读。因此,当您使用此处理程序开始运动更新时,运动的姿态属性将不再可以更改。但是 motionManager.deviceMotion 的态度属性设置为您在 startDeviceMotionUpdatesUsingReferenceFrame 中指定的任何值,并且当您使用 startDeviceMotionUpdatesUsingReferenceFrame 开始运动更新时,它会被读入对象。 a 对象现在具有正确的姿态,而 motion 对象具有默认姿态。

关于iphone - 带有引用框架的 CoreMotion iOS 5 态度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7918091/

相关文章:

iOS 5 Twitter API 在模拟器与真实 iOS 设备中的行为不同

iphone - 在 iOS 上,有没有办法直接改变或绘制到 CGImage 而不是绘制到 Graphics Context 然后转换整个东西?

iphone - NSURL 连接在 3g 上失败 'network connection was lost'

ios - UITableView 一次仅勾选一行

ios - 添加自定义推送通知声音iOS5无法正常工作

iphone - 在 Objective-C 中实现消息链接机制?

ios - 企业 iOS 开发者计划

iphone - 如何在iPhone应用程序的表格单元格中加载背景图像

ios - 当某些按钮隐藏时,快速自动布局会更改按钮位置

ios - iPhone/iPad 之间不同效果的 CALayer