Conor Taylor
Conor Taylor

Reputation: 3108

Slowing down a while loop that is moving an image view

When I call this method:

- (void)method:(int)i {
    while (image[i].center.y <= 100) {
        image[i].center = CGPointMake(image[i].center.x, image[i].center.y+2);
    }
}

The loop instantly runs and the image is instantly brought to the point where y=100. Is there a way of slowing this (or an alternative I am unaware of) that will let the image visually move or accelerate to the point rather that instantly moving to it?

Upvotes: 2

Views: 213

Answers (2)

Dustin
Dustin

Reputation: 6803

Try using code similar to this:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
image.center = CGPointMake(image.center.x, image.center.y-moveAmount);
[UIView commitAnimations];

Upvotes: 2

epatel
epatel

Reputation: 46051

It seems like you are looking to make an animation, maybe something like this.

- (void)method:(int)i {
   [UIView animateWithDuration:2.0
                    animations:^{ 
                      image[i].center = CGPointMake(image[i].center.x, 100);
                    }];
}

I recommend you read this

http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

Upvotes: 7

Related Questions