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];

    }];

}

 

posted @ 2016-03-22 16:59  偶阵雨ss33  Views(361)  Comments(0Edit  收藏  举报