私は、色の選択を通じてアニメーションへのビューのbackgroundColorの要件があるiOSアプリケーションを構築しています。私のviewDidLoadメソッドでは、基本的に次を使用してUIViewアニメーションのチェーンを起動しています。
-(void) beginFirstStageBackgroundAnimation
{
[UIView animateWithDuration: 3.0f
delay: 3.0f
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.view.backgroundColor = [UIColor colorWithRed: 251./255 green:203./255 blue:147./255 alpha:1.0];
}
completion:^(BOOL finished){
[self secondStageBackgroundAnimation];
}
];
}
完了ハンドラーは、次の色を含む2番目のメソッドを起動します。
-(void) secondStageBackgroundAnimation
{
[UIView animateWithDuration: 3.0f
delay: 3.0f
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.view.backgroundColor = [UIColor colorWithRed:251./255 green:224./255 blue:96./255 alpha:1.0];
}
completion:^(BOOL finished){
[self thirdStageBackgroundAnimation];
}
];
}
など...これは、7番目のアニメーションで[self beginFirstStageBackgroundAnimation];
、プロセスを再開するために完了を呼び出すまで続きます。
戻るボタンでビューを離れるとき、viewDidDisappearで、またはディスプレイのタイマーが終了するとき[self.view.layer removeAllAnimations];
、アニメーションを完全に取り除くために実行します。ただし、アプリは意図したとおりに実行および動作しますが、ビューを離れて全体を実行するとクラッシュするようです。理由はわかりませんが、このアニメーションチェーンに関連しているようです。
3秒の遅延で3秒ごとにビューのbackgroundColorをアニメーション化するためのより良い解決策はありますか?
そして、[self.view.layer removeAllAnimations];
実際に私がやりたいことをしますか?
編集:私がビューを離れるコードは次のとおりです:
-(void) backBtnPressed:(id)sender
{
[self stopAudio]; // stop audio that is playing.
[self.view.layer removeAllAnimations]; // remove all animations?
[self.navigationController popViewControllerAnimated: YES]; // pop view from stack
}