我用这个解决了我的问题:
- (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];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1224 次 |
| 最近记录: |