1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- //
- // ActivityIndicatorView.m
- // DGActivityIndicatorExample
- //
- // Created by 小花 on 2018/11/1.
- // Copyright © 2018年 Danil Gontovnik. All rights reserved.
- //
- #import "ActivityIndicatorView.h"
- #import "ActivityIndicatorAnimation.h"
- static ActivityIndicatorView *_indicatorView = nil;
- @implementation ActivityIndicatorView
- + (instancetype)shareIndicatorView {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _indicatorView = [[ActivityIndicatorView alloc] initWithTintColor:@[[UIColor colorWithHex:0xFE6461],[UIColor colorWithHex:0xFFE000],[UIColor colorWithHex:0x66D8FF]] size:50];
- _indicatorView.frame = CGRectMake(0, 0, 100 , 100) ;
- });
- return _indicatorView;
- }
- - (id)initWithTintColor:(NSArray *)tintColors size:(CGFloat)size {
- self = [super init];
- if (self) {
- _size = size;
- _tintColors = tintColors;
- }
- return self;
- }
- + (instancetype)showInView:(UIView *)superView frame:(CGRect)frame {
- ActivityIndicatorView *indicatorView = [[ActivityIndicatorView alloc] initWithTintColor:@[[UIColor colorWithHex:0xFE6461],[UIColor colorWithHex:0xFFE000],[UIColor colorWithHex:0x66D8FF]] size:50];
- indicatorView.frame = frame;
- indicatorView.backgroundColor = [UIColor whiteColor];
- [indicatorView startAnimating];
- [superView addSubview:indicatorView];
- return indicatorView;
- }
- #pragma mark -
- #pragma mark Methods
- - (void)setupAnimation {
- self.layer.sublayers = nil;
- ActivityIndicatorAnimation *animation = [[ActivityIndicatorAnimation alloc] init];
- [animation setupAnimationInLayer:self.layer withSize:CGSizeMake(_size, _size) tintColor:_tintColors];
- self.layer.speed = 0.0f;
-
- }
- - (void)startAnimating {
- if (!self.layer.sublayers) {
- [self setupAnimation];
- }
- self.layer.speed = 1.0f;
- _animating = YES;
- }
- - (void)stopAnimating {
- self.layer.speed = 0.0f;
- [self removeFromSuperview];
- _animating = NO;
-
- }
- @end
|