Device motion detection in iOS

2019-06-08 01:50发布

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..

0条回答
登录 后发表回答