现在,我正在使用以下代码从设备的陀螺仪获取Euler值。这是应该使用的方式吗?还是没有使用NSTimer的更好的方法?
- (void)viewDidLoad {
[super viewDidLoad];
CMMotionManager *motionManger = [[CMMotionManager alloc] init];
[motionManger startDeviceMotionUpdates];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:(1/6) target:self selector:@selector(read) userInfo:nil repeats:YES];
}
- (void)read {
CMAttitude *attitude;
CMDeviceMotion *motion = motionManger.deviceMotion;
attitude = motion.attitude;
int yaw = attitude.yaw;
}
最佳答案
你可以用这个...
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error)
{
CMAttitude *attitude;
attitude = motion.attitude;
int yaw = attitude.yaw;
}];
关于objective-c - 我是否需要使用NSTimer从iOS陀螺仪获取数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13985280/