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. 分组password算法

    代换,S盒.扩散和混淆,这些概念构成了分组password学的基础. 假设明文和密文的分组长度都为n比特,则明文的每个分组都有2n个可能的取值; 代换: 为使加密运算可逆(即解密运算可行),明文的每个 ...

  2. 真正的Java学习从入门到精通

    http://www.it.com.cn/f/edu/059/6/169189.htm 一. 工具篇JDK (Java Development Kit) JDK是整个Java的核心,包括了Java运行 ...

  3. 摘录 LDAP

    1.LDAP就是 light DAP, 轻量级目录访问协议     LDAP是轻量目录访问协议(Lightweight Directory Access Protocol)的缩写     LDAP标准 ...

  4. C# Html Agility Pack

    using System; using HtmlAgilityPack; using System.IO; using System.Text; using System.Text.RegularEx ...

  5. 在freemarker文件中,html标签获取后台的值

    1.<#assign a='3333' /> 2.<input type="text" id="name" name="name&q ...

  6. centos 防火墙开放80端口

    辛辛苦苦编译安装完Ngnix,mysql ,PHP,后发现不能访问,后来发现是防火墙把80端口给禁用了.开启之:(以下参考自:http://llhdf.javaeye.com/blog/526176) ...

  7. 走进科学之揭开神秘的"零拷贝"!

        "零拷贝"这三个字,想必大家多多少少都有听过吧,这个技术在各种开源组件中都使用了,比如kafka,rocketmq,netty,nginx等等开源框架都在其中引用了这项技术 ...

  8. 常用PHP array数组函数

    array_rand  第二个参数用来确定要选出几个元素 如果选出的元素不止一个,则返回包含随机键名的数组,否则返回该元素的键名. $a=array("red","gre ...

  9. windows 和 linux 上 循环读取文件名称的区别和方法

    function showGetFileName($type){ $url="/opt/mobile_system/gscdn"; //另一台服务器映射到linux过来的路径. # ...

  10. Java应用一般架构

    转载一下文章: 自己连看三便方的其要点精髓. 当我们架设一个系统的时候通常需要考虑到如何与其他系统交互,所以我们首先需要知道各种系统之间是如何交互的,使用何种技术实现. 1. 不同系统不同语言之间的交 ...