iOS - PNG Animation 圖片動畫

用圖片串成動畫有點類似翻頁書方式

可直接在viewDidLoad當中加入
//new 一個ImageView來播放動畫,大小與ViewController相同
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:self.view.frame];

//把所有的圖片依照順序都丟進這陣列中
animationImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"CM1.png"],
[UIImage imageNamed:@"CM2.png"],
[UIImage imageNamed:@"CM3.png"],
[UIImage imageNamed:@"CM4.png"],
[UIImage imageNamed:@"CM5.png"],
[UIImage imageNamed:@"CM6.png"],
[UIImage imageNamed:@"CM7.png"],
[UIImage imageNamed:@"CM8.png"],
[UIImage imageNamed:@"CM9.png"], nil];

//動畫全部的播放時間 單位:秒
animationImageView.animationDuration = 9.42;
//總共要播放幾次,0 = 播放無限循環
animationImageView.animationRepeatCount = 2;
//開始播放動畫
[animationImageView startAnimating];
//把ImageView丟進ViewController的View中
[self.view addSubview:animationImageView];
//由於addSubView會自動將retainCoint加1,所以釋放一個ImageView
[animationImageView release];


相關連結
iOS Developer Library
iOS Developer Library - UIImageView Class Reference

沒有留言:

張貼留言