您的位置:首页 > 产品设计 > UI/UE

用UIImgeView播放gif图

2015-09-19 09:13 375 查看


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];
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: