No Description

FKLoadingView.m 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // FKLoadingView.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 2016/10/25.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKLoadingView.h"
  9. @interface FKLoadingView ()
  10. @property (nonatomic, strong) UIImageView *bgImageView;
  11. @property (nonatomic, strong) UIImageView *loadingIcon;
  12. @end
  13. @implementation FKLoadingView
  14. /*
  15. // Only override drawRect: if you perform custom drawing.
  16. // An empty implementation adversely affects performance during animation.
  17. - (void)drawRect:(CGRect)rect {
  18. // Drawing code
  19. }
  20. */
  21. - (instancetype)init {
  22. self = [super init];
  23. if (self) {
  24. self.backgroundColor = [UIColor clearColor];
  25. [self addAllSubviews];
  26. }
  27. return self;
  28. }
  29. #pragma mark - Method
  30. - (void)startAnimation {
  31. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
  32. animation.byValue = @(M_PI * 2);
  33. animation.duration = 0.7f;
  34. animation.repeatCount = INFINITY;
  35. [self.loadingIcon.layer removeAllAnimations];
  36. [self.loadingIcon.layer addAnimation:animation forKey:@"sd"];
  37. }
  38. #pragma mark - Layout
  39. - (void)addAllSubviews {
  40. [self addSubview:self.bgImageView];
  41. [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.centerX.equalTo(self);
  43. make.centerY.equalTo(self).offset(-8);
  44. make.size.mas_equalTo(CGSizeMake(60, 60));
  45. }];
  46. [self.bgImageView addSubview:self.loadingIcon];
  47. [self.loadingIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.centerX.equalTo(self.bgImageView);
  49. make.centerY.equalTo(self.bgImageView).offset(-2);
  50. make.size.mas_equalTo(CGSizeMake(24, 24));
  51. }];
  52. }
  53. #pragma mark - Property
  54. - (UIImageView *)bgImageView {
  55. if (!_bgImageView) {
  56. _bgImageView = [UIImageView new];
  57. _bgImageView.image = [UIImage imageNamed:@"CustomLoadingBgIcon"];
  58. }
  59. return _bgImageView;
  60. }
  61. - (UIImageView *)loadingIcon {
  62. if (!_loadingIcon) {
  63. _loadingIcon = [UIImageView new];
  64. _loadingIcon.image = [UIImage imageNamed:@"CustomLoadingIcon"];
  65. }
  66. return _loadingIcon;
  67. }
  68. @end