【问题标题】:iOS gyroscope to make virtual horizoniOS 陀螺仪制作虚拟地平线
【发布时间】:2012-05-06 16:48:30
【问题描述】:

我希望使用陀螺仪为我的应用添加一个虚拟地平线 like this one

我找到了很多关于陀螺仪的文档,我想我使用偏航但我不知道如何用重力校准。

有人可以帮帮我吗??

谢谢。

【问题讨论】:

  • 这篇 SO 帖子是否回答了您的问题? stackoverflow.com/questions/3723985/…
  • 感谢 ajmccall 的回复,但没有。我想制作一个视觉地平线,就像上面的链接一样,我知道如何获取信息来旋转我的图层,但它在我启动应用程序的位置被初始化。我想在地平线的真实位置启动我的图层。谢谢。

标签: ios gyroscope


【解决方案1】:

我用这个解决了我的问题:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多