0

オブジェクトのx と y の位置を傾きの量から更新するにはどうすればよいですか?

傾きの動きの量に基づいて、 _bgオブジェクトのxと y の位置を更新しようとしています。

また、デバイスをテーブルに置いた場合、位置は元の位置に戻る必要があります。

私はこのようなことをしようとしています:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    _motionManager = [[CMMotionManager alloc] init];

    [_motionManager startGyroUpdates];
    _timer = [NSTimer scheduledTimerWithTimeInterval:1/30
                                              target:self
                                            selector:@selector(updateGyro)
                                            userInfo:nil repeats:YES];
}



- (void)updateFromGyro
{
    self.x += _motionManager.gyroData.rotationRate.x;
    self.y += _motionManager.gyroData.rotationRate.y;

    _bg.center = CGPointMake(self.x, self.y);
}

問題は、オブジェクトの動きが止まらないことです。

ありがとうございました!

4

3 に答える 3