0

我想像全景图一样沿直线跟踪设备沿 X 轴的运动。

我尝试使用加速度计,但无法跟踪。

我认为它只检测设备旋转。我搜索了很多关于灰度、磁力计等的教程。

任何人都可以提供核心运动的样本吗?

帮我解决这个问题。

谢谢你。

我的代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    xval=0;
    motionManager = [[CMMotionManager alloc] init];
    motionManager.deviceMotionUpdateInterval = 1.0/60.0;
    NSOperationQueue *aQueue = [NSOperationQueue alloc];
    [motionManager startDeviceMotionUpdatesToQueue:aQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
        NSLog(@"X value is: %f", motion.userAcceleration.x);
        if (motion.userAcceleration.x > 0.05) {
            //a solid move forward starts
            //lineLength++; //increment a line length value
            xval=xval+10;
            ball.frame=CGRectMake(xval, 361, 119, 104);
        }
        if (motion.userAcceleration.x < -0.02 ) {
            [motionManager stopDeviceMotionUpdates];
        }
    }];
}
4

0 回答 0