【发布时间】:2012-05-06 16:48:30
【问题描述】:
【问题讨论】:
-
这篇 SO 帖子是否回答了您的问题? stackoverflow.com/questions/3723985/…
-
感谢 ajmccall 的回复,但没有。我想制作一个视觉地平线,就像上面的链接一样,我知道如何获取信息来旋转我的图层,但它在我启动应用程序的位置被初始化。我想在地平线的真实位置启动我的图层。谢谢。
【问题讨论】:
我用这个解决了我的问题:
- (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];
}];
【讨论】: