1

I'm trying to stack two animations. I use the same UIImage in my code for both images. I start by determining (first line) WHAT image to load.

NSString *imageName = (self._handleToSectionModel.calculatorState == CALCULATOR_OPENED)? 
[NSString stringWithString:@"1_dg_please_see_warning_2lines.png"] : 
[NSString stringWithString:@"1_dg_warnings_landing_page.png"];

I want to fade OUT the current image, and load the new image and FADE it in. Obviously when I execute this it only really animates the second one. What's the correct way to stack animations to the same View so they both run fully?

UIImage *image = [UIImage imageNamed:imageName];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];

self.warningImage.alpha = 0.0f;

[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];

self.warningImage.alpha = 1.0f;
self.warningImage.image = image;

[UIView commitAnimations];

EDIT / UPDATE: SOLVED:

    [UIView animateWithDuration:1.0 animations:^{ self.warningImage.alpha = 0.0f; } completion:^(BOOL finished){
        [UIView animateWithDuration:1.0 animations:^{ self.warningImage.alpha = 1.0f; self.warningImage.image = image; } completion:^(BOOL finished){}];
    }];

Thanks to the link in my comment!

mr-sk
  • 13,174
  • 11
  • 66
  • 101
  • Wow, just found this: http://stackoverflow.com/questions/3849460/best-way-to-perform-several-sequential-uiview-animations – mr-sk May 19 '11 at 16:59

1 Answers1

1
[UIView animateWithDuration:1.0 animations:^{ self.warningImage.alpha = 0.0f; } completion:^(BOOL finished){
    [UIView animateWithDuration:1.0 animations:^{ self.warningImage.alpha = 1.0f; self.warningImage.image = image; } completion:^(BOOL finished){}];
}];
mr-sk
  • 13,174
  • 11
  • 66
  • 101