12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // AccompanyLoadingView.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2022/8/15.
- //
- #import "AccompanyLoadingView.h"
- #import <Lottie/Lottie.h>
- @interface AccompanyLoadingView ()
- @property (weak, nonatomic) IBOutlet UIView *loadContainer;
- @property (nonatomic, strong) LOTAnimationView *animationView;
- @property (nonatomic, strong) NSString *jsonString;
- @property (nonatomic, copy) AccompanyLoadingCallback callback;
- @end
- @implementation AccompanyLoadingView
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.jsonString = @"cloud_animation";
- }
- - (void)loadingCallback:(AccompanyLoadingCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- + (instancetype)shareInstance {
- AccompanyLoadingView *view = [[[NSBundle mainBundle] loadNibNamed:@"AccompanyLoadingView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)showLoading {
- self.layer.opacity = 1.0f;
- if (self.animationView.isAnimationPlaying) {
- return;
- }
- if (![self.loadContainer.subviews containsObject:self.animationView]) {
- [self.loadContainer addSubview:self.animationView];
- [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.loadContainer);
- }];
- }
- [self.animationView play];
- }
- - (void)stopLoading {
- if (self.animationView.isAnimationPlaying) {
- [self.animationView stop];
- }
- [UIView animateWithDuration:1.0f animations:^{
- self.layer.opacity = 0.0f;
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- }];
- }
- - (IBAction)cancleAction:(id)sender {
- if (self.animationView.isAnimationPlaying) {
- [self.animationView stop];
- }
-
- if (self.callback) {
- self.callback();
- }
- }
- - (LOTAnimationView *)animationView {
- if (!_animationView) {
- _animationView = [LOTAnimationView animationNamed:self.jsonString];
- _animationView.contentMode = UIViewContentModeScaleAspectFill;
- _animationView.animationSpeed = 1.0;
- _animationView.loopAnimation = YES;
- }
- return _animationView;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|