zoukankan      html  css  js  c++  java
  • LoadingView 自定义加载图片

    #import <UIKit/UIKit.h>

    @interface LoadingView : UIView

    @property (nonatomic,strong) NSMutableArray *giftImageArray;

    +(id)showLoadingView;

    +(void)hidenLoadingView:(LoadingView *)loadingView;

     @end

    #import "LoadingView.h"

    - (instancetype)init

    {

        self = [super init];

        if (self) {

            self.frame = CGRectMake( 0, 0, ScreenWidth, ScreenHeight);

            

            UIView *backView = [[UIView alloc]initWithFrame:CGRectMake( 0, 0, ScreenWidth, ScreenHeight)];

            backView.backgroundColor = [UIColor blackColor];

            backView.alpha = 0.7;

            [self addSubview:backView];

        }

        return self;

    }

    +(id)showLoadingView{

        LoadingView *loadingView = [[LoadingView alloc]init];

        

        NSMutableArray *array = [NSMutableArray array];

        for (int i = 0; i < 7; i++) {

            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat: @"loading_da%d",i+1]];

            [array addObject:image];

        }

        UIImageView *loading = [[UIImageView alloc]initWithFrame:CGRectMake( ScreenWidth/2-Width(77), ScreenHeight/2 - Width(77), Width(154), Width(154))];

        [loadingView addSubview:loading];

        [UIView animateWithDuration:1 animations:^{

            

        } completion:^(BOOL finished) {

            loadingView.giftImageArray = array;

            loading.animationDuration = 0.7;

            loading.animationImages = loadingView.giftImageArray;

            loading.animationRepeatCount = 0;

            loading.image = [loadingView.giftImageArray firstObject];

            

            [loading startAnimating];

        }];

        [loadingView show];

        

        return loadingView;

    }

    +(void)hidenLoadingView:(LoadingView *)loadingView{

        [loadingView performSelector:@selector(hide) withObject:nil afterDelay:0.4];

    }

    //添加 背景灰度

    - (void)show{

        //添加到window上 就不需要再次添加到self.view上了

        UIWindow *win = [[UIApplication sharedApplication] keyWindow];

        UIView *topView = [win.subviews objectAtIndex:0];

        

        [topView addSubview:self];

        

        

        [UIView animateWithDuration:0.1 animations:^{

            [self layoutIfNeeded];

        }];

    }

    - (void)hide{

        

        [UIView animateWithDuration:0.1 animations:^{

            self.alpha = 0;

            

            [self layoutIfNeeded];

        } completion:^(BOOL finished) {

            [self removeFromSuperview];

        }];

    }

  • 相关阅读:
    C语言编程 两种方法打印一个菱形(渐入显示)
    Java编程格式输出中 printf 的使用实例
    C语言编程输入一个5位数以内的正整数,完成以下操作
    C语言编程判断两个矩阵是否相等(n阶矩阵)
    C语言编程输出100到200的素数的两种方法,和三步优化(逐步优化)
    Java编程中Math.random()的应用(随机生成数的应用)
    C语言编程求1X2X3····Xn所得的数末尾有多少个零
    C语言大数的阶乘
    maven构建一个简单的springboot项目
    nginx的配置
  • 原文地址:https://www.cnblogs.com/lrr0618/p/5307447.html
Copyright © 2011-2022 走看看