Device motion detection in iOS

2019-06-08 02:19发布

问题:

I want to detect the device motion like Panorama i.e. motion from my left side to Right side.

I tried with the accelerometer but i can't able to do it.

I like to move one image in a straight line as the device move.

My code is as follow:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1/60];
    [[UIAccelerometer sharedAccelerometer]setDelegate:self];
}

pragma mark - Accelerometer Delegate

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:
(UIAcceleration *)acceleration{

    valueX = acceleration.x*100.0;
    valueY = acceleration.y*30.0;

    float newX = (float)(ball.center.x + valueX);

    CGPoint newCenter = CGPointMake(newX, 50);
    ball.center = newCenter;

}

How can I do this? Because there are many apps who uses this.

Please guide me.

Thanks..