• 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
  • 相关阅读:
    Android内存管理篇
    Android内存管理篇
    Java:ServiceLoader未加载服务提供实现类
    Java:SPI机制
    利用向量积(叉积)计算三角形的面积和多边形的面积
    VMware虚拟机安装WinXP出现错误output error file to the following location A:GHOSTERR.TXT
    @media与css先后顺序产生的优先级问题
    css 始终显示滚动条,内容超出显示有滑块的滚动条,内容没有超出显示空的滚动条
    css 内容溢出显示垂直滚动条,内容不超出就不显示滚动条
    css 一行或多行文字溢出以...的形式隐藏
  • 原文地址:https://www.cnblogs.com/oc-bowen/p/5234418.html
Copyright © 2020-2023  润新知