Search code examples
iosobjective-cuiimageview

Animation in viewDidLoad


For some reason, my animation only works when executed through an IBAction but not through the viewDidLoad. I want these images to start animating right when the view loads.

myImageView.animationImages = [NSArray arrayWithObjects:
                              [UIImage imageNamed:@"image1.png"],
                              [UIImage imageNamed:@"image2.png"], nil];
[myImageView setAnimationRepeatCount:0];
myImageView.animationDuration = 2;
[myImageView startAnimating];

Solution

  • Move your animation from viewDidLoad to viewDidAppear. You are not able to animate the components of your view until it has finished laying out.