Attempting to stack to UIView annimations
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.warni开发者_开发技巧ngImage.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!
[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){}];
}];
精彩评论