KSCustomLoadingView.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // KSCustomLoadingView.m
  3. // GuanYueTeamTeacher
  4. //
  5. // Created by 王智 on 2023/2/2.
  6. //
  7. #import "KSCustomLoadingView.h"
  8. #import <Lottie/Lottie.h>
  9. @interface KSCustomLoadingView ()
  10. @property (weak, nonatomic) IBOutlet UIView *containerView;
  11. @property (weak, nonatomic) IBOutlet UILabel *text;
  12. @property (nonatomic, strong) LOTAnimationView *animationView;
  13. @end
  14. @implementation KSCustomLoadingView
  15. + (instancetype)shareInstance {
  16. KSCustomLoadingView *view = [[[NSBundle mainBundle] loadNibNamed:@"KSCustomLoadingView" owner:nil options:nil] firstObject];
  17. return view;
  18. }
  19. - (void)showLoadingView {
  20. UIWindow *windows = [NSObject getKeyWindow];
  21. [windows addSubview:self];
  22. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.left.right.top.bottom.mas_equalTo(windows);
  24. }];
  25. [self.containerView addSubview:self.animationView];
  26. [self.animationView mas_remakeConstraints:^(MASConstraintMaker *make) {
  27. make.left.right.top.bottom.mas_equalTo(self.containerView);
  28. }];
  29. [self.animationView play];
  30. }
  31. - (void)hideLoadingView {
  32. if (self.animationView.isAnimationPlaying) {
  33. [self.animationView stop];
  34. }
  35. [self removeFromSuperview];
  36. }
  37. - (LOTAnimationView *)animationView {
  38. if (!_animationView) {
  39. _animationView = [LOTAnimationView animationNamed:@"teacher_refresh"];
  40. _animationView.contentMode = UIViewContentModeScaleAspectFill;
  41. _animationView.animationSpeed = 1.0;
  42. _animationView.loopAnimation = YES;
  43. }
  44. return _animationView;
  45. }
  46. - (void)setDisplayText:(NSString *)displayText {
  47. _displayText = displayText;
  48. self.text.text = displayText;
  49. }
  50. /*
  51. // Only override drawRect: if you perform custom drawing.
  52. // An empty implementation adversely affects performance during animation.
  53. - (void)drawRect:(CGRect)rect {
  54. // Drawing code
  55. }
  56. */
  57. @end