iOS显示GIF图片(3中方法)
2015-12-25 17:36
453 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。
先倒入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
先倒入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
相关文章推荐
- iOS开发封装一个可以响应超链接的label——基于RCLabel的交互扩展
- iOS可执行文件瘦身方法
- iOS把对象直接转化成NSDictionary或JSON
- IOS文件系统
- ios音量振动条
- iOS当期时间和日期选择器
- iOS简单的音效播放单例 (您可照搬代码)
- IOS开发——获取本地音频文件(属性/信息)
- IOS平台音频处理API介绍
- iOS 真机调试双击.cer证书
- iOS可变数组添加元素 以及可变数组操作
- iOS项目重构周记(一)
- iOS项目重构周记(二)
- iOS的三种多线程技术
- iOS开发笔记--连续跳转上层页面
- iOS从xib界面跳转到storyboard 中的界面和从storyboard中的界面跳转到另一个storyboard中的界面
- iOS--代码关联storyboard
- 处理动态类型的方法
- iOS 触摸事件五:手势处理器
- iOS学习之 plist文件的读写