LaunchAnimationView.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // LaunchAnimationView.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/7/26.
  6. //
  7. #import "LaunchAnimationView.h"
  8. #import <Lottie/Lottie.h>
  9. @interface LaunchAnimationView ()
  10. @property (nonatomic, strong) LOTAnimationView *loadingView;
  11. @property (nonatomic, strong) NSString *jsonString;
  12. @property (nonatomic, copy) LaunchFinishCallback callback;
  13. @end
  14. @implementation LaunchAnimationView
  15. - (void)launchAnimationFinish:(LaunchFinishCallback)callback {
  16. if (callback) {
  17. self.callback = callback;
  18. }
  19. }
  20. - (instancetype)init {
  21. self = [super init];
  22. if (self) {
  23. }
  24. return self;
  25. }
  26. - (void)configUI {
  27. self.backgroundColor = [UIColor whiteColor];
  28. [self setJsonName:@"launchAni.json"];
  29. }
  30. - (void)setJsonName:(NSString *)jsonName {
  31. self.jsonString = jsonName;
  32. [self addSubview:self.loadingView];
  33. MJWeakSelf;
  34. [self.loadingView playWithCompletion:^(BOOL animationFinished) {
  35. [weakSelf successBack];
  36. }];
  37. }
  38. - (void)successBack {
  39. if (self.callback) {
  40. self.callback();
  41. }
  42. }
  43. - (LOTAnimationView *)loadingView {
  44. if(_loadingView == nil) {
  45. //1.加载本地json
  46. _loadingView = [LOTAnimationView animationNamed:self.jsonString];
  47. //2.加载后台给的json(url)
  48. _loadingView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
  49. _loadingView.loopAnimation = YES;
  50. _loadingView.contentMode = UIViewContentModeScaleAspectFill;
  51. _loadingView.animationSpeed = 1.0;
  52. _loadingView.loopAnimation = NO;
  53. }
  54. return _loadingView;
  55. }
  56. /*
  57. // Only override drawRect: if you perform custom drawing.
  58. // An empty implementation adversely affects performance during animation.
  59. - (void)drawRect:(CGRect)rect {
  60. // Drawing code
  61. }
  62. */
  63. @end