• 封装 加载loading动画


    #import <UIKit/UIKit.h>

     @interface SSLoading : UIView

     - (instancetype)initWithFrame:(CGRect)frame;

    - (void)showLoading:(UIColor *)backgroundColor alpha:(CGFloat)alpha;

    -(void)disMiss;

     @end

     

     

    #import "SSLoading.h"

    #import "UIImage+GIF.h"

     

     

    @implementation SSLoading

    {

        UIView *SSLoadingBackView;

        UIImageView *SSLoadingImageView;

    }

    - (instancetype)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            self.hidden = YES;

            self.frame = frame;

        }

        return self;

     

    }

     

    - (void)showLoading:(UIColor *)backgroundColor alpha:(CGFloat)alpha

    {

        

        self.hidden = NO;

        

        SSLoadingBackView = [[UIView alloc] initWithFrame:self.frame];

        SSLoadingBackView.backgroundColor = backgroundColor;

        SSLoadingBackView.alpha = alpha;

        [self addSubview:SSLoadingBackView];

        

        NSString  *name = @"loading@2x.gif";

        NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];

        NSData  *imageData = [NSData dataWithContentsOfFile:filePath];

        if (!SSLoadingImageView) {

            SSLoadingImageView = [[UIImageView alloc]init];

        }

        

        SSLoadingImageView.backgroundColor = [UIColor clearColor];

        SSLoadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];

        SSLoadingImageView.frame = CGRectMake(self.frame.size.width/2-50, self.frame.size.height/2-50, 100, 100);

        SSLoadingImageView.contentMode = UIViewContentModeScaleAspectFit;

        [self addSubview:SSLoadingImageView];

    }

     

    -(void)disMiss

    {

        

        for (UIView *view in self.subviews) {

            [view removeFromSuperview];

        }

        self.hidden = YES;

    }

  • 相关阅读:
    爱福窝在线装修设计软件测评
    关于简书首页模式的思考和畅想
    这些O2O比你们更靠谱儿
    iOS动画——Layer Animations
    最大流, 最小割问题及算法实现
    浅谈iOS学习之路
    iOS架构师之路:慎用继承
    iOS架构师之路:控制器(View Controller)瘦身设计
    IOS中的编码规范
    关闭键盘导致tableView:didSelectRowAtIndexPath:失效解决办法
  • 原文地址:https://www.cnblogs.com/xiaolingling1126/p/5485062.html
Copyright © 2020-2023  润新知