1.代碼如下 (註釋都有) - (void)viewDidLoad { [super viewDidLoad]; UIImageView * bigImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100) ...
1.代碼如下 (註釋都有)
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView * bigImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
// 創建儲存圖片的數組
NSMutableArray * imageArray = [NSMutableArray array];
for (int i=1; i<19; i++)
{
// 拼接字元串圖片名
NSString * imageString = [NSString stringWithFormat:@"zixun_%d",i];
// 根據圖片獲取圖片名
UIImage * image = [UIImage imageNamed:imageString];
// 添加圖片到數組
[imageArray addObject:image];
}
// gif圖片組
bigImageView.animationImages = imageArray;
// 播放的速率
bigImageView.animationDuration = 3;
// 播放次數
bigImageView.animationRepeatCount = 1;
// 開始動畫
[bigImageView startAnimating];
//添加子視圖到view
[self.view addSubview:bigImageView];
}