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. ios 使用gcd 显示倒计时

    __block ;//倒计时时间 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ...

  2. nginx做反向代理proxy_pass,proxy_redirect的使用

     大 | 中 | 小  今天用nginx作为trac的反代,发现一个问题,就是登入登出跳转的时候是白页,看了下网页相应内容,发现相应的location是空的.查了一下发现是只单纯用了proxy_pas ...

  3. android开发中遇到的问题汇总【九】

    244.http请求的url含有中字符时.须要Uri编码.Uri.encoder() 245.使用androidstudio时,不知道什么原因svn不见了 Android Studio missing ...

  4. sublime使用技巧(4)-- 其他技巧【持续更新】

    命令模式 1.切换语言格式,ctrl + shirt + p 2.简化操作 ctrl + shirt + p 输入 snippet:function 自动生成function的基本结构!tab键 移动 ...

  5. 第四篇: Ansible 常用模块使用

    一. command | shell 模块 该模块为:执行命令模块 (由于命令模块较为强大,可根据自身对操作系统的熟练程度而增加.所以这里不再介绍类似可以实现同功能模块,比如service模块,需要重 ...

  6. json性能测试

    http://www.open-open.com/lib/view/open1434377191317.html

  7. Lumen开发:添加手机验证,中文验证与Validator验证的“半个”生命周期

    版权声明:本文为博主原创文章,未经博主允许不得转载. 添加手机验证方法可直接看这里:https://www.cnblogs.com/cxscode/p/9609828.html 今天来讲一下,Lume ...

  8. windows安装apache

    由于个人有强迫倾向,下载软件都喜欢从官网下载,摸索了好久终于摸清楚怎么从Apache官网下载windows安装版的Apache服务器了,现在分享给大家.   工具/原料   apache 方法/步骤 ...

  9. leetCode 57.Insert Interval (插入区间) 解题思路和方法

    Insert Interval  Given a set of non-overlapping intervals, insert a new interval into the intervals ...

  10. Android hellocharts 柱形图详解

    近日需要做图表结构的项目,目前最火的就是hellocharts  和MPAndroidChart  相对来说hellocharts集成比较简单: 官网地址   https://github.com/l ...