gif 图 是多张依次有连续动作的图 顺时间展示的一种动态效果图 .   有的是均匀时间更换下一张  有的 则不是均匀时间变化

1. 那么 对于均匀 时间变化的gif图 比较适合 使用 iOS 系统自带方法 imageView 的动态展示图片的方法就好

如:

NSMutableArray *array=[NSMutableArray arrayWithCapacity:];
for(int i=;i < 10;i++)
{
NSString *str=[NSString stringWithFormat:@"Nav_Bg%d.png",i];
UIImage *image=[UIImage imageNamed:str];
[array addObject:image];
}
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imageView.animationImages=array;
imageView.animationDuration=1.5;//duration :持续 持续时间
imageView.animationRepeatCount=1 ;//重复次数
[self .window addSubview:imageView];
[imageView startAnimating];

以上code  表达的是 10张图 在 1.5的时间 只执行一次动画展示(不循环重复)   所以关键 是这个 1.5秒 需要表达10张图 正常一次执行的时间即可出现效果比较好的动画

2.  不确定时间gif

上述方法 是按照 给定的常量时间 1.5s 执行gif 时间, 这样的弊端 是 如果把当前方法作为通用的类方法的话,这个1.5s 很不科学 . 所以 下边的方法是首先计算图片的总时间长度 .再执行动画.

#import <UIKit/UIKit.h>
@interface MotionActiveAgeGif : UIView
{
UIImageView *gitView;
}
@property (nonatomic ,strong) UIImageView *gitView;
@property (nonatomic ,strong)UIImageView * lastGifView;
//@property (nonatomic ,strong)NSString * gifName;
- (instancetype)initWithName:(NSString *)gifName andFrame:(CGRect)frame ;
@end #import "MotionActiveAgeGif.h" #import <ImageIO/ImageIO.h>
#import <QuartzCore/CoreAnimation.h> //#define DuringTime 1.5f
@interface MotionActiveAgeGif ()
{
float totalTime ;
CADisplayLink *displayLink ;
}
@end
@implementation MotionActiveAgeGif
@synthesize gitView ;
@synthesize lastGifView ;
- (instancetype)initWithName:(NSString *)gifName andFrame:(CGRect)frame
{
self = [super init];
if (self) {
totalTime = 0;
gitView = [[UIImageView alloc]initWithFrame:frame];
lastGifView = [[UIImageView alloc]initWithFrame:gitView.frame];
NSURL *url = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"%@.gif",gifName] withExtension:nil];
CGImageSourceRef csf = CGImageSourceCreateWithURL((__bridge CFTypeRef) url, NULL);
size_t const count = CGImageSourceGetCount(csf);
UIImage *frames[count];
CGImageRef images[count]; NSMutableArray *delayTimes = [NSMutableArray array];
for (size_t i = 0; i < count; ++i) {
images[i] = CGImageSourceCreateImageAtIndex(csf, i, NULL);
UIImage *image =[[UIImage alloc] initWithCGImage:images[i]];
lastGifView.image = image ;
frames[i] = image; //CFBridgingRelease 给予arc所有权
NSDictionary *dict = (NSDictionary*)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(csf, i, NULL));
NSLog(@"kCGImagePropertyGIFDictionary %@", [dict valueForKey:(NSString*)kCGImagePropertyGIFDictionary]);
//
NSDictionary *gifDict = [dict valueForKey:(NSString*)kCGImagePropertyGIFDictionary];
[delayTimes addObject:[gifDict valueForKey:(NSString*)kCGImagePropertyGIFDelayTime]]; if (totalTime >= 0)
{
totalTime = totalTime + [[gifDict valueForKey:(NSString*)kCGImagePropertyGIFUnclampedDelayTime] floatValue];
}
NSLog(@"%lf",totalTime); CFRelease(images[i]);
}
UIImage *const animation = [UIImage animatedImageWithImages:[NSArray arrayWithObjects:frames count:count] duration:totalTime];
gitView.image = animation;
gitView.animationRepeatCount =1; //动画重复次数1 不起作用
[gitView startAnimating];
[self addSubview:gitView];
self.frame = gitView.frame; [self performSelector:@selector(stopGifView) withObject:nil afterDelay:totalTime];
CFRelease(csf);
}
return self;
}
- (void)stopGifView
{
[gitView removeFromSuperview];
[self addSubview:lastGifView];
}

iOS 展示 gif的更多相关文章

  1. vue iframe嵌套页面高度自适应 (ios 宽度扩大的bug , ios展示比例问题)

    <template>   <div class="card-index pt-relative">     <div id="wrapper ...

  2. iOS 展示二级页面

    ViewController 调用 #import "ViewController.h" @implementation ViewController - (void)viewDi ...

  3. 通读SDWebImage③--gif和webP的支持、不同格式图片的处理、方向处理

    本文目录 NSData+ImageContentType: 根据NSData获取MIME UIImage+GIF UIImage+WebP UIImage+MultiFormat:根据NSData相应 ...

  4. SDWebImage源码阅读-第三篇

    这一篇讲讲不常用的一些方法. 1 sd_setImageWithPreviousCachedImageWithURL: placeholderImage: options: progress: com ...

  5. uni-app开发小程序入门到崩溃

    最近一段时间公司要做一个小程序项目,还要支持,微信小程序,头条小程序,百度小程序.一套代码,实现三个平台.当时接到这个任务,就不知道怎么去下手,一套代码,分别要发布三个平台,赶紧就去上网了解这些东西, ...

  6. 爱了!阿里大神最佳总结“Flutter进阶学习笔记”,理论与实战

    前言 "小步快跑.快速迭代"的开发大环境下,"一套代码.多端运行"是很多开发团队的梦想,美团也一样.他们做了很多跨平台开发框架的尝试:React Native. ...

  7. Ionic中使用Chart.js进行图表展示以及在iOS/Android中的性能差异

    Angular Chart 简介 在之前的文章中介绍了使用 Ionic 开发跨平台(iOS & Android)应用中遇到的一些问题的解决方案. 在更新0.1.3版本的过程中遇到了需要使用图表 ...

  8. iOS开发——UI进阶篇(一)UITableView,索引条,汽车数据展示案例

    一.什么是UITableView 在iOS中,要实现展示列表数据,最常用的做法就是使用UITableViewUITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳 UIT ...

  9. iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序

    iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序 一.plist文件和项目结构图 说明:这是一个嵌套模型的示例 二.代码示例: YYcarsgroup.h文件代码: // // YYcar ...

随机推荐

  1. linux程序设计——取消一个线程(第十二章)

    12.7    取消一个线程 有时,想让一个线程能够要求还有一个线程终止,就像给它发送一个信号一样. 线程有方法能够做到这一点,与与信号处理一样.线程能够被要求终止时改变其行为. pthread_ca ...

  2. Mysql的建表规范与注意事项

    一. 表设计规范 库名.表名.字段名必须使用小写字母,“_”分割. 库名.表名.字段名必须不超过12个字符. 库名.表名.字段名见名知意,建议使用名词而不是动词. 建议使用InnoDB存储引擎. 存储 ...

  3. Dalvik opcodes 查询smali语法大全

    原文链接:http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html Vx values in the table denote a Dalvik ...

  4. 工作总结 无法确定条件表达式的类型,因为“<null>”和“System.DateTime”之间没有隐式转换 解决办法 object——Nullable<T> (可空类型)

    可空值类型 备注     一种类型认为是可以为 null,如果它可以分配一个值,也可以分配null,这意味着类型具有无论如何没有值. 默认情况下,所有都引用类型,如String,是否可以为 null, ...

  5. 用Scratch2.0源码定制一个自己的编辑器

    用Scratch2.0源码定制一个自己的编辑器,换成自己的软件名称和图标,添加中文字体,修复汉化错误等等1.准备:下载Scratch2.0源码.安装开发工具Adobe Flash Builder4.7 ...

  6. android dp 和 px 的相互转换

    在开发中,可能须要动态设置控件的大小 比如为一个gridview设置宽度: LinearLayout.LayoutParams linearParams2 = (LinearLayout.Layout ...

  7. Spring事务管理之声明式事务管理:基于TransactionProxyFactoryBean的方式

    © 版权声明:本文为博主原创文章,转载请注明出处 案例 - 利用Spring的声明式事务(TransactionProxyFactoryBean)管理模拟转账过程 数据库准备 -- 创建表 CREAT ...

  8. GO语言使用开源SSH模拟终端

    <pre name="code" class="plain">package main import ( "go-ssh/ssh" ...

  9. android studio改动module名称

    新建一个android studio项目,默认Module名称是app 右键app选择Rename,或者Shift + F6也能够.重命名module名称 重命名为abc之后中,如图上面箭头所指的ap ...

  10. Arcgis:坐标系统极其转换

    1. ArcGIS中的坐标系统 ArcGIS中预定义了两套坐标系统,地理坐标系(Geographic coordinate system)和投影坐标系(Projectedcoordinate syst ...