Pavne
Pavne

Reputation: 89

How can i move the image object smoothly when I am using accelerometer in iOS?

In my app I am moving the ball according to the accelerometer movements but the ball not moved smoothly .I need to move the ball smoothly on view.How can i?

I used below statements by searching on google.but i didn't get the smooth object

delta.x = 0.01 * delta.x + (1.0 - 0.01) * acceleration.x;
delta.y = 0.01 * delta.y + (1.0 - 0.01) * acceleration.y;

Upvotes: 0

Views: 1001

Answers (2)

Rafeek
Rafeek

Reputation: 533

use

[UIView beginAniations:@"AnimaionName" context:nil];

[UIView setAnimationDuration: 2.0f];

imageView.frame = CGRectMake(,,,);

[UIView commitAnimation];

This will provide smooth movement

Upvotes: 0

Rushi
Rushi

Reputation: 4500

Try :

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    point = CGPointMake(34*acceleration.x, -20*acceleration.y);
    image.center = CGPointMake(image.center.x+point.x,image.center.y);

}

Upvotes: 1

Related Questions