iOS显示GIF图片(3中方法)

版权声明:本文为博主原创文章,未经博主允许不得转载。



先倒入GifView.h、GifView.m 类


#import "ViewController.h"

#import "GifView.h"

@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    

    //1. 第三方

    // 网络图片

    //  NSData *urlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.chinagif.com/gif/part/boy/0045.gif"]]; 

    

    // 本地图片 

    NSData *localData = [NSDatadataWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"run"ofType:@"gif"]]; 

    

   GifView *dataView = [[GifViewalloc] initWithFrame:CGRectMake(0,0, 100, 100) data:localData];  

    [self.viewaddSubview:dataView];

    [dataViewrelease];

    

    // 或者

    

    GifView *pathView =[[GifViewalloc] initWithFrame:CGRectMake(100,0, 100,100) filePath:[[NSBundlemainBundle] pathForResource:@"run"ofType:@"gif"]];

    [self.viewaddSubview:pathView];

    [pathViewrelease];

    

    //2. webView   

    

    NSString *path = [[NSBundlemainBundle] pathForResource:@"run"ofType:@"gif"];

   NSData *gifData = [NSDatadataWithContentsOfFile:path];

   UIWebView *webView = [[UIWebViewalloc] initWithFrame:CGRectMake(0,120, 100, 100)];

    webView.backgroundColor = [UIColorredColor];

    webView.scalesPageToFit =YES;

    [webView loadData:gifDataMIMEType:@"image/gif"textEncodingName:nilbaseURL:nil];

    [self.viewaddSubview:webView];

    [webViewrelease];

    

    //3. animationView

    

   UIImageView *gifImageView = [[UIImageViewalloc] initWithFrame:CGRectMake(0,240, 100, 100)];

    NSArray *gifArray = [NSArrayarrayWithObjects:[UIImageimageNamed:@"1"],

                         [UIImageimageNamed:@"2"],

                         [UIImageimageNamed:@"3"],

                         [UIImageimageNamed:@"4"],

                         [UIImageimageNamed:@"5"],

                         [UIImageimageNamed:@"6"],

                         [UIImageimageNamed:@"7"],

                         [UIImageimageNamed:@"8"],

                         [UIImageimageNamed:@"9"],

                         [UIImageimageNamed:@"10"],

                         [UIImageimageNamed:@"11"],

                         [UIImageimageNamed:@"12"],

                         [UIImageimageNamed:@"13"],

                         [UIImageimageNamed:@"14"],

                         [UIImageimageNamed:@"15"],

                         [UIImageimageNamed:@"16"],

                         [UIImageimageNamed:@"17"],

                         [UIImageimageNamed:@"18"],

                         [UIImageimageNamed:@"19"],

                         [UIImageimageNamed:@"20"],

                         [UIImageimageNamed:@"21"],

                         [UIImageimageNamed:@"22"],nil];

    gifImageView.animationImages = gifArray;//动画图片数组

    gifImageView.animationDuration =5; //执行一次完整动画所需的时长

    gifImageView.animationRepeatCount =999//动画重复次数

    [gifImageViewstartAnimating];

    [self.viewaddSubview:gifImageView];

    [gifImageViewrelease];

}

    


- (void)viewDidUnload

{

    [superviewDidUnload];

    // Release any retained subviews of the main view.

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return (interfaceOrientation !=UIInterfaceOrientationPortraitUpsideDown);

}


@end






转载请注明出处http://blog.csdn.net/sevenquan


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值