iOS开发_UIImageView 播放多张图片动画

UIImageView *playImageV = [[UIImageView alloc] init];
[self addSubview:playImageV];
playImageV.frame = self.bounds;

// 创建图片集
NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:0];

for (NSInteger index = 1; index < 30; index++) {
    NSString *image_name = [NSString stringWithFormat:@"%ld.jpg", (long)index];
    UIImage *tempImage = [UIImage imageNamed:image_name];
    // 添加图片
    [imageArray addObject:tempImage];
}

// 播放图片集
// 设置播放的图片集(需将图片添加到数组 imageArray 中)
playImageV.animationImages = imageArray;
// 设置播放整个图片集的时间
playImageV.animationDuration = 29;
// 设置循环播放次数,默认为 0 一直循环
playImageV.animationRepeatCount = 0;
// 开始播放
[playImageV startAnimating];

// 停止播放动画
// [playImageV stopAnimating];
posted @ 2018-07-26 22:51  CH520  阅读(288)  评论(0编辑  收藏  举报