2 つのアニメーションをスタックしようとしています。両方の画像のコードで同じ 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"];
現在の画像をフェード アウトし、新しい画像をロードしてフェード インしたいと考えています。明らかに、これを実行すると、実際には 2 番目の画像だけがアニメーション化されます。アニメーションを同じビューにスタックして両方を完全に実行する正しい方法は何ですか?
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){}];
}];
私のコメントのリンクに感謝します!