酷店

ActivityIndicatorView.m 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // ActivityIndicatorView.m
  3. // DGActivityIndicatorExample
  4. //
  5. // Created by 小花 on 2018/11/1.
  6. // Copyright © 2018年 Danil Gontovnik. All rights reserved.
  7. //
  8. #import "ActivityIndicatorView.h"
  9. #import "ActivityIndicatorAnimation.h"
  10. static ActivityIndicatorView *_indicatorView = nil;
  11. @implementation ActivityIndicatorView
  12. + (instancetype)shareIndicatorView {
  13. static dispatch_once_t onceToken;
  14. dispatch_once(&onceToken, ^{
  15. _indicatorView = [[ActivityIndicatorView alloc] initWithTintColor:@[[UIColor colorWithHex:0xFE6461],[UIColor colorWithHex:0xFFE000],[UIColor colorWithHex:0x66D8FF]] size:50];
  16. _indicatorView.frame = CGRectMake(0, 0, 100 , 100) ;
  17. });
  18. return _indicatorView;
  19. }
  20. - (id)initWithTintColor:(NSArray *)tintColors size:(CGFloat)size {
  21. self = [super init];
  22. if (self) {
  23. _size = size;
  24. _tintColors = tintColors;
  25. }
  26. return self;
  27. }
  28. + (instancetype)showInView:(UIView *)superView frame:(CGRect)frame {
  29. ActivityIndicatorView *indicatorView = [[ActivityIndicatorView alloc] initWithTintColor:@[[UIColor colorWithHex:0xFE6461],[UIColor colorWithHex:0xFFE000],[UIColor colorWithHex:0x66D8FF]] size:50];
  30. indicatorView.frame = frame;
  31. indicatorView.backgroundColor = [UIColor whiteColor];
  32. [indicatorView startAnimating];
  33. [superView addSubview:indicatorView];
  34. return indicatorView;
  35. }
  36. #pragma mark -
  37. #pragma mark Methods
  38. - (void)setupAnimation {
  39. self.layer.sublayers = nil;
  40. ActivityIndicatorAnimation *animation = [[ActivityIndicatorAnimation alloc] init];
  41. [animation setupAnimationInLayer:self.layer withSize:CGSizeMake(_size, _size) tintColor:_tintColors];
  42. self.layer.speed = 0.0f;
  43. }
  44. - (void)startAnimating {
  45. if (!self.layer.sublayers) {
  46. [self setupAnimation];
  47. }
  48. self.layer.speed = 1.0f;
  49. _animating = YES;
  50. }
  51. - (void)stopAnimating {
  52. self.layer.speed = 0.0f;
  53. [self removeFromSuperview];
  54. _animating = NO;
  55. }
  56. @end