以下を発展させた内容ですが、
http://blog.suz-lab.com/2010/03/uiimageviewiphone.html
UIImageViewには連続画像をアニメーションとして表示する機能があります。
下記のようなコードで、00.png〜14.pngまでの画像を、
0.5秒でアニメーションし、さらに、それを10回繰り返すことができます。
(画像を普通に表示するコードと対応させています)
--------【画像を普通に表示】--------
- (void)viewDidLoad {
[super viewDidLoad];
imageView.image = [UIImage imageNamed:@"test.png"];
}
--------【画像をアニメーションと表示】--------
- (void)viewDidLoad {
[super viewDidLoad];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"00.png"],
[UIImage imageNamed:@"01.png"],
[UIImage imageNamed:@"02.png"],
[UIImage imageNamed:@"03.png"],
[UIImage imageNamed:@"04.png"],
[UIImage imageNamed:@"05.png"],
[UIImage imageNamed:@"06.png"],
[UIImage imageNamed:@"07.png"],
[UIImage imageNamed:@"08.png"],
[UIImage imageNamed:@"09.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
[UIImage imageNamed:@"13.png"],
[UIImage imageNamed:@"14.png"],
nil
];
imageView.animationDuration = 0.5f;
imageView.animationRepeatCount = 10;
[imageView startAnimating];
}
--------
ポイントは下記の通りです。
(1) animationImagesにUIImageの配列を代入。
(2) 上記配列の最後の要素はnilでなければならない。
(3) アニメーションの時間はanimationDurationで指定。
(4) アニメーションの繰り返し回数はanimationRepeatCountで指定。
(5) animationRepeatCountを0にすると永遠に繰り返す。
(6) [imageView startAnimating]でアニメーション開始。
2月のブログの記事数が、目標より下回ってしまった…
--------
http://www.suz-lab.com

0 コメント:
コメントを投稿