Reputation: 107
I am trying to make a simple animation. I want to move an UIImageView to the right by using [UIView animateWithDuration....
Here is my code:
file.h
{
IBOutlet UIImageView *moveImage;
}
file.m
- (void)viewDidLoad
{
[super viewDidLoad];
//Move Image
moveImage.center = CGPointMake(moveImage.center.x, moveImage.center.y);
[UIView animateWithDuration:2.0
animations:^{ moveImage.center = CGPointMake(moveImage.center.x + 60.0, moveImage.center.y); }];
}
When I run the iOS Simulator it shows the image at the new x coordinate, but it doesn't show the animation. Any help would be greatly appreciated. Thank you in advance.
Upvotes: 2
Views: 101
Reputation: 25692
You should use ViewDidAppear Not ViewDidLoad
ViewDidLoad means View was loaded to memory, but not drawn. So you can't see the animation at that point.
viewDidAppear means View was drawn. So you can animate after view was shown.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
moveImage.center = CGPointMake(moveImage.center.x, moveImage.center.y);
[UIView animateWithDuration:2.0
animations:^{ moveImage.center = CGPointMake(moveImage.center.x + 60.0, moveImage.center.y); }];
}
Upvotes: 6