美文网首页
小轮子:loading

小轮子:loading

作者: dc630f46ee2d | 来源:发表于2017-12-20 13:53 被阅读0次
    #import <UIKit/UIKit.h>
    
    @interface DishLoadingView : UIView
    + (DishLoadingView *)sharedInstance;
    - (void)show;
    - (void)hide;
    @end
    
    
    #import "DishLoadingView.h"
    #import "Masonry.h"
    
    @interface DishLoadingView ()
    @property (nonatomic, strong) UIImageView *imageView;
    @end
    
    @implementation DishLoadingView
    + (DishLoadingView *)sharedInstance {
        static DishLoadingView *loadingView = nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            loadingView = [[DishLoadingView alloc] init];
        });
        return loadingView;
    }
    
    - (instancetype)init {
        self = [super init];
        if (self) {
            UIImageView *imageView = [[UIImageView alloc] init];
            [self addSubview:imageView];
            [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.mas_equalTo(self);
                make.size.mas_equalTo(CGSizeMake(50, 50));
            }];
            NSMutableArray *loadingImgs = [[NSMutableArray alloc] initWithCapacity:75];
            for (NSInteger i = 1; i <= 74; i++) {
                UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"loading_%02ld", i]];
                [loadingImgs addObject:img];
            }
            imageView.animationImages = loadingImgs;
            imageView.animationDuration = 2;
            imageView.animationRepeatCount = 0;
            self.imageView = imageView;
        }
        return self;
    }
    
    - (void)show {
        [self removeFromSuperview];
        UIView *superView = [UIApplication sharedApplication].delegate.window;
        [superView addSubview:self];
        [self mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(superView);
        }];
        [self startAnimation];
    }
    
    - (void)startAnimation {
        [self.imageView startAnimating];
    }
    
    - (void)stopAnimation {
        [self.imageView stopAnimating];
    }
    
    - (void)hide {
        [self stopAnimation];
        [self removeFromSuperview];
    }
    
    
    @end
    

    相关文章

      网友评论

          本文标题:小轮子:loading

          本文链接:https://www.haomeiwen.com/subject/gpbcmxtx.html