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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值