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. 每天一个JavaScript实例-展示设置和获取CSS样式设置

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. <context:annotation-config/>、<context:component-scan/>

    在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredA ...

  3. debian SSD ext4 4K 对齐

    新入手了一台thinkpad, 原来的机械硬盘是500G的, 于是购入一块镁光的MX200 250G的SSD来新装debian stable(jessie) 1, 安装系统的之前按住F1进入bios后 ...

  4. userService 用户 会员 系统设计 v2 q224 .doc

    userService 用户 会员 系统设计 v2 q224 .doc 1. Admin  login1 2. 普通用户注册登录2 2.1. <!-- 会员退出登录 -->2 2.2. & ...

  5. tensorflow-gpu 1.13 提示找不到 libcublas.so.10.0 的问题

    tensorflow-gpu 使用 1.13.1,cuda-10-0已安装好,但启动时依然报错 ImportError: libcublas.so.10.0: cannot open shared o ...

  6. JavaScript事件使用指南

    事件流 事件流描述的是从页面中接收事件的顺序,IE和Netscape提出来差不多完全相反的事件流的概念,IE事件流是事件冒泡流,Netscape事件流是事件捕获流. 事件冒泡 IE的事件流叫做事件冒泡 ...

  7. pwd 命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  8. 下载并导出数据到execl中

    下载poi-3.6-20091214.jar.下载地址例如以下: http://download.csdn.net/detail/evangel_z/3895051 1.jsp <button ...

  9. openWRT自学计划安排

    目标:充分理解openwrt的框架构成,能够在openwrt框架下实现:开发新程序,修改现有程序,修改内核,修改boot.为此,制定如下计划: 一.如何在openwrt上做开发 1.编译出一个BRCM ...

  10. 交易应用及网站驱动不兼容Windows 10的解决方案

        微软公司于2015年7月29日正式发布了Windows 10操作系统.全球范围内已有数以千万计的用户踊跃地升级到了Windows 10,在新用户享受Windows 10所带来的全新使用体验的同 ...