用UIImgeView播放gif图

这里写图片描述

RootViewController.m
#import "RootViewController.h"
@interface RootViewController ()

1.创建一个UIImageView的属性.
@property(nonatomic, retain)UIImageView *imageView;

@end

@implementation RootViewController

- (void)dealloc
{
    [_imageView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];

    2.创建一个UIImageView.
    self.imageView = [UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200);
    [self.view addSubview:self.imageView];
    [_imageView release];

    3.创建一个可变数组.
    NSMutableArray *picArray = [NSMutableArray array];
    4.遍历图片张数,有多少张遍历多少次.
    for (NSInteger i = 0; i < 40; i++) {
        5.做一次打印,使用02ld占位.
        NSLog(@"%02ld", i);
        6.拼接图片名,找到对应的图片位置.
        NSString *imageName = [NSString stringWithFormat:@"eat_%02ld.jpg", i];
        7.打印图片名称,验证图片名是否以拼接完成.
        NSLog(@"%@", imageName);
        8.将拼接好的图片放入UIImage类的对象中.
        UIImage *image = [UIImage imageNamed:imageName];
        9.UIImage对象,放入数组中.
        [picArray addObject:image];
    }

    10.确定要播放动画的数组.
    self.imageView.animationImages = picArray;
    11.动画的持续时间.
    self.imageView.animationDuration = 0.1;
    12.动画播放的重复.
    self.imageView.animationRepeatCount = 0;
    13.动画开始播放.
    [self.imageView startAnimation];
}

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值