2012-05-06 126 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]; 
               }];