Reputation: 109
I want to make an IBAction
that when called makes an image move a certain amount of pixels "fluidly." I have one now that make the image move 10 pixels to the left but it just kind of teleports there. I want the image to move over, almost like its walking not magically ending up there.
here is what I have:
- (IBAction)moveImageLeft:(id)sender
{
y = y + 10;
myImageView.frame = CGRectMake(x, y, 45, 56);
}
Upvotes: 0
Views: 146
Reputation: 130222
@Dimple's answer is correct. However, just for reference purposes, here's another way of doing it. It's called an animation block and in my opinion makes the whole animation process a lot easier.
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
y = y + 10;
myImageView.frame = CGRectMake(x, y, 45, 56);
}completion:^(BOOL finishedAnimating){
if (finishedAnimating == YES) {
NSLog(@"animation finished");//you can put your own completion handler events here
}
}];
Upvotes: 5
Reputation: 6954
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
y = y + 10;
myImageView.frame = CGRectMake(x, y, 45, 56);
[UIView commitAnimations];
Upvotes: 2