2012-05-06 122 views
6

我期待包括使用陀螺仪我的应用程序虚拟地平线虚拟水平,like this oneiOS的陀螺仪,使

我发现很多文档上的陀螺,我想我使用偏航,但我不知道如何校准重力。

有人可以帮我吗?

谢谢。

+0

这是否SO张贴回答您的问题? http://stackoverflow.com/questions/3723985/calibrating-code-to-iphone-acellerometer-and-gyro-data – ajmccall

+0

谢谢你的答复ajmccall,但没有。我想制作一个视觉地平线,就像上面的链接一样,我知道如何获取信息来旋转我的图层,但是它是在启动应用程序的位置初始化的。我想在地平线的真实位置启动我的图层。谢谢。 – doc

回答

7

我解决我的问题与此:

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