IOS-加载动态图(gif)

  1 //
  2 //  BowenView.h
  3 //  IOS_0302_下拉刷新
  4 //
  5 //  Created by ma c on 16/3/2.
  6 //  Copyright © 2016年 博文科技. All rights reserved.
  7 //
  8
  9 #import <UIKit/UIKit.h>
 10
 11 @interface BowenView : UIView
 12
 13 //要把loading界面加载到那个界面
 14 + (void)showBowenViewFromSuperView:(UIView *)superView;
 15 //要把loading界面从哪个界面移除
 16 + (void)removeBowenViewFromSuperView:(UIView *)superView;
 17 //要把loading界面加载到那个界面上(具体位置)
 18 + (void)showBowenViewFromSuperView:(UIView *)superView offSetY:(CGFloat)offSetY;
 19
 20 @end
 21
 22
 23
 24
 25 //
 26 //  BowenView.m
 27 //  IOS_0302_下拉刷新
 28 //
 29 //  Created by ma c on 16/3/2.
 30 //  Copyright © 2016年 博文科技. All rights reserved.
 31 //
 32
 33 #import "BowenView.h"
 34
 35 @interface BowenView ()
 36
 37 //动态图
 38 @property (nonatomic, strong) UIImageView *loadingImgView;
 39 //提示文字
 40 @property (nonatomic, strong) UILabel *lbl;
 41
 42 @end
 43
 44
 45
 46 @implementation BowenView
 47
 48
 49 - (instancetype)init
 50 {
 51     self = [super init];
 52     if (self) {
 53         [self addSubview:self.loadingImgView];
 54         [self addSubview:self.lbl];
 55     }
 56     return self;
 57 }
 58
 59 - (UIImageView *)loadingImgView
 60 {
 61     if(!_loadingImgView){
 62         _loadingImgView = [[UIImageView alloc] init];
 63         _loadingImgView.frame = CGRectMake(0, 0, 80, 80);
 64         _loadingImgView.backgroundColor = [UIColor clearColor];
 65         //动态图属性
 66         _loadingImgView.animationImages = [self getImageArray];
 67         _loadingImgView.animationDuration = 2.0;
 68         _loadingImgView.animationRepeatCount = 0;
 69     }
 70     return _loadingImgView;
 71 }
 72
 73 - (UILabel *)lbl
 74 {
 75     if(!_lbl){
 76         _lbl = [[UILabel alloc] init];
 77         _lbl.frame = CGRectMake(0, 80, 80, 30);
 78         _lbl.text = @"正在加载...";
 79         _lbl.font = [UIFont systemFontOfSize:14];
 80         _lbl.textColor = [UIColor darkGrayColor];
 81         _lbl.textAlignment = NSTextAlignmentCenter;
 82     }
 83     return _lbl;
 84 }
 85 //获取图片数组
 86 - (NSArray *)getImageArray
 87 {
 88     NSMutableArray *imgArray = [NSMutableArray array];
 89     NSMutableArray *imgNameArr = [NSMutableArray array];
 90
 91     for (int i=1; i<16; i++) {
 92
 93          NSString *imgName = [NSString stringWithFormat:@"loading_animate_%02d",i];
 94         [imgArray addObject:imgName];
 95     }
 96
 97     for (int i = 0; i < 15; i ++) {
 98         UIImage *image = [UIImage imageNamed:[imgArray objectAtIndex:i]];
 99         [imgNameArr addObject:image];
100     }
101     return imgNameArr;
102
103
104 }
105
106 //要把loading界面加载到那个界面
107 + (void)showBowenViewFromSuperView:(UIView *)superView
108 {
109     [self showBowenViewFromSuperView:superView offSetY:0];
110 }
111 //要把loading界面从哪个界面移除
112 + (void)removeBowenViewFromSuperView:(UIView *)superView
113 {
114     //在父视图的【所有子视图数组中】查找
115     for (UIView *itemView in superView.subviews) {
116         if ([itemView isKindOfClass:[BowenView class]]) {
117             [itemView removeFromSuperview];
118         }
119     }
120 }
121 //要把loading界面加载到那个界面上(具体位置)
122 + (void)showBowenViewFromSuperView:(UIView *)superView offSetY:(CGFloat)offSetY
123 {
124     BowenView *loadingView = [[BowenView alloc] init];
125     loadingView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2 - 40, 200 + offSetY, 100, 80);
126
127     //判断superView上是否已经存在一个BowenView,如果已经存在,先删除,在加载新的View
128     [self removeBowenViewFromSuperView:superView];
129     [superView addSubview:loadingView];
130
131     //让动态图动起来
132     [loadingView.loadingImgView startAnimating];
133
134
135 }
136
137 @end
时间: 2024-08-05 17:36:40

IOS-加载动态图(gif)的相关文章

iOS加载动态图的两种方法

一 view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; NSString *imagePath =[[NSBundle mainBundle] pathForResource:@"csjg" ofType:@"gif"]; CGImageSourceRef  cImageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSU

iOS 加载动态库报错问题

dyld: Library not loaded: @rpath Referenced from: Reason: no suitable image found.  Did find: 要么使用静态库,要么General -> Embedded Binaries

Unity使用脚本进行批量动态加载贴图

先描述一下我正在做的这个项目,是跑酷类音游. 那么跑酷类音游在绘制跑道上的时候,就要考虑不同的砖块显示问题.假设我有了一个节奏列表,那么我们怎么将不同的贴图贴到不同的砖块上去呢? 我花了好几个小时才搞清楚里面的门路,且听我慢慢道来. 首先我们建立一个地图,在上面新建一个Empty Object,将所有的Road砖块全部划分到这个分组里. 效果图如下: 我们得到了一些预制块,接下来我们要将其染上色. 首先的问题是,我们怎么遍历这些砖块呢?很简单,用Tag.我们将所有的砖块打上一个特别的tag,"r

简易仿ios菊花加载loading图

原文链接:https://mp.weixin.qq.com/s/wBbQgOfr59wntNK9ZJ5iRw 项目中经常会用到加载数据的loading显示图,除了设计根据app自身设计的动画loading,一般用的比较多的是仿照ios 的菊花加载loading 图,当然一些条件下还会涉及到加载成功/ 失败情况的显示,还有显示文字. 使用ProgressBar 来加载动画转圈,这里使用drawable文件 定义转圈动画,indeterminateDrawable属性进行加载. <?xml vers

iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?

Apple官方的文档为生成一个UIImage对象提供了两种方法: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数也是图片文件的路径. 那么两种有什么区别吗? 肯定是有的.根据Apple的官方文档: imageNamed: 这个方法用一个指定的名字在系统缓存中查找并返回一个图片对象如果它存在的话.如果缓存中没有找到相应的图片,这个方法从指定的文档中加载然后缓存并返回这个对象.因此imageNamed的优点是当加载时会缓存图片.所以当图

【转载】cocos2dx 中 Android NDK 加载动态库的问题

原文地址:http://blog.csdn.net/sozell/article/details/10551309 cocos2dx 中 Android NDK 加载动态库的问题 闲聊 最近在接入各个平台的SDK,遇到了不少问题,也从中了解了不少知识,之前一直觉得没啥好写的,毕竟做了4个月的游戏开发,也没有碰上什么真正的大问题,cocos2dx的引擎包得也很好,能让人把大部分时间都关注在游戏逻辑.效果的处理上,当然,之前的libevent还是小坑一下,但是和后来遇到的相比,也算不上什么了. 我最

NGINX 加载动态模块(NGINX 1.9.11开始增加加载动态模块支持)

NGINX 1.9.11开始增加加载动态模块支持,从此不再需要替换nginx文件即可增加第三方扩展.目前官方只有几个模块支持动态加载,第三方模块需要升级支持才可编译成模块. [email protected]:~/nginx-1.12.0$ ./configure --help | grep dynamic --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module --with-http_image_filter_mo

Android 高清加载巨图方案 拒绝压缩图片

Android 高清加载巨图方案 拒绝压缩图片

Ubuntu linux设置从当前目录下加载动态库so文件

linux的excutable在执行的时候缺省是先搜索/lib和/usr/lib这两个目录,然后按照ld.so.conf里面的配置搜索绝对路径,linux缺省是不会在当前目录搜索动态库的.windows加载动态库的时候,缺省是首先加载本地目录下的动态库,然后再搜索windows/system和windows/system32目录. windows的动态库搜索顺序,虽然有可能会造成潜在的混乱,但是对于开发和测试无疑是比较方便的,尤其是debug和release版本的动态库需要经常切换进行测试的时候

浅谈DevExpress&lt;三&gt;:在GridView中加载动态图片

今天的演示效果如下:在GridView中的下拉框中选中一种颜色,则后面的加载相应的图片,如下图: 1. 2. 3. 下面说下实现方法:首先在项目中拉一个GirdControl,在里面创建4列:ID,Name,Color,Image,并将Color和Image分别创建repositoryItemComboBox和repositoryItemPictureEdit控件,如下图: 将一个图片文件夹放到程序的启动目录中: 文件夹中包含如下图片: 接下来进行创建数据模板,先创建一个Datetable,添加