展現(xiàn)動態(tài)圖
UIImageView*myView = [[UIImageView alloc] init]; ? ??//創(chuàng)建UIImageView對象
myView.frame=CGRectMake(100,100,200,200);
[self.view addSubview:myView];
[myView release];
NSMutableArray*arr = [[NSMutableArray alloc] init]; ? ??//創(chuàng)建可變數(shù)組用來裝載UIImage對象
for(int i =0; i <5; i++) { ? ??// for循環(huán)將圖片添加進(jìn)UIImage中
NSString*str = [NSString stringWithFormat:@"%02d.tiff", i+1]; ??//獲得字符串名字
UIImage*image = [UIImageimage Named:str]; ? ? ?//通過靜態(tài)圖片名字創(chuàng)建UIImage對象
[arr addObject:image]; ? ? ? ??//再將UIImage對象裝載到數(shù)組中
}
myView.animationImages= arr; ? ? ? ??//將裝載好靜態(tài)圖數(shù)組賦值給UIImageView自帶的動畫數(shù)組中
myView.animationRepeatCount=8; ? ? ? ?//設(shè)置動畫重復(fù)次數(shù)(默認(rèn)無限次)
myView.animationDuration=0.1 * ? arr.count; ? ? ? ??//設(shè)置動畫播放時間
[myView startAnimating]; ? ? ? ? ?//啟動動畫
循環(huán)中字符串名字前面的數(shù)字(如下圖)的給入需要用 %2d自動填滿
例如:要想實現(xiàn) 012 ?008 這樣的三位數(shù) 就應(yīng)當(dāng)用 %3d。