シンプルなアニメーション[iPhone]
-
06-07-2019 - |
質問
他の無関係なものと一緒に画面の中央で押されたときに、短い5〜10フレームのアニメーションをトリガーするUIButtonがいくつかあります。 IBに1つのUIImageViewをドロップして、それを何らかの方法でプログラムで更新できますか?過度に複雑である必要はありません。ハードコーディングされているかどうかは気にしません。今のところ、このような小さなプロジェクトだからです。
ありがとう。
解決
ここに、ほんの数フレームでアニメーションを作成する最も簡単な方法の例を示します。
IBOutlet UIImageView * timerAnimation
を宣言し、それをIBのUIIMageViewにリンクします。以下に必要な画像をいくつかリソースに追加します。次に、画像を配列に読み込みます-コードを参照してください:
timerAnimation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"timer00.png"],
[UIImage imageNamed:@"timer01.png"],
[UIImage imageNamed:@"timer02.png"],
[UIImage imageNamed:@"timer03.png"],
[UIImage imageNamed:@"timer04.png"],
[UIImage imageNamed:@"timer05.png"],
[UIImage imageNamed:@"timer06.png"],
[UIImage imageNamed:@"timer07.png"],
[UIImage imageNamed:@"timer08.png"],
[UIImage imageNamed:@"timer09.png"],
[UIImage imageNamed:@"timer10.png"],
[UIImage imageNamed:@"timer11.png"],
[UIImage imageNamed:@"timer12.png"],
[UIImage imageNamed:@"timer13.png"],
[UIImage imageNamed:@"timer14.png"],
[UIImage imageNamed:@"timer15.png"],
[UIImage imageNamed:@"timer16.png"],
[UIImage imageNamed:@"timer17.png"],
[UIImage imageNamed:@"timer18.png"],
[UIImage imageNamed:@"timer19.png"],
[UIImage imageNamed:@"timer20.png"],
[UIImage imageNamed:@"timer21.png"],
[UIImage imageNamed:@"timer22.png"],
[UIImage imageNamed:@"timer23.png"],
[UIImage imageNamed:@"timer24.png"],
[UIImage imageNamed:@"timer25.png"],
[UIImage imageNamed:@"timer26.png"],
[UIImage imageNamed:@"timer27.png"],
[UIImage imageNamed:@"timer28.png"],
[UIImage imageNamed:@"timer29.png"],
[UIImage imageNamed:@"timer30.png"],
[UIImage imageNamed:@"timer31.png"],
[UIImage imageNamed:@"timer32.png"],
[UIImage imageNamed:@"timer33.png"],
[UIImage imageNamed:@"timer34.png"],
[UIImage imageNamed:@"timer35.png"],
// [UIImage imageNamed:@"timer36.png"], save last picture for "times up"
nil];
timerAnimation.animationDuration = 5.0;
timerAnimation.animationRepeatCount = 1;
[timerAnimation startAnimating];
[timerAnimation stopAnimating];
所属していません StackOverflow