1

我正在尝试堆叠两个动画。我在两个图像的代码中使用相同的 UIImage。我首先确定(第一行)要加载的图像。

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

我想淡出当前图像,并加载新图像并将其淡入。显然,当我执行此操作时,它只会真正为第二个图像设置动画。将动画堆叠到同一个视图以使它们都完全运行的正确方法是什么?

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];

编辑/更新:已解决:

    [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){}];
    }];

感谢我评论中的链接!

4

1 回答 1

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){}];
}];
于 2011-05-20T19:16:36.530 回答