123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // KSGifRefreshHeader.m
- // StudentDaya
- //
- // Created by Kyle on 2021/10/15.
- // Copyright © 2021 DayaMusic. All rights reserved.
- //
- #import "KSGifRefreshHeader.h"
- #import <Lottie/Lottie.h>
- @interface KSGifRefreshHeader ()
- @property(nonatomic, strong) LOTAnimationView *loadingView;
- @property(nonatomic, strong) NSString *jsonString;
- @end
- @implementation KSGifRefreshHeader
- - (instancetype)init {
- if (self = [super init]) {
- self.lastUpdatedTimeLabel.hidden = YES;
- self.stateLabel.hidden = YES;
- [self setJsonName:@"student_refresh"];
- }
- return self;
- }
- - (void)setJsonName:(NSString *)jsonName {
- self.jsonString = jsonName;
- [self addSubview:self.loadingView];
- }
- - (LOTAnimationView *)loadingView {
- if(_loadingView == nil) {
- //1.加载本地json
- _loadingView = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:self.jsonString ofType:@"json"]];
- //2.加载后台给的json(url)
- _loadingView.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width / 2.0) - 45, 0, 90, 50);
- _loadingView.loopAnimation = YES;
- _loadingView.contentMode = UIViewContentModeScaleAspectFill;
- _loadingView.animationSpeed = 1.0;
- _loadingView.loopAnimation = YES;
- }
- return _loadingView;
- }
- #pragma mark - innerMethod
- - (void)endRefreshing {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [super endRefreshing];
- });
- }
- #pragma mark - 监听控件的刷新状态
- - (void)setState:(MJRefreshState)state {
- MJRefreshCheckState;
- if(self.jsonString.length > 0) {
- switch (state) {
- case MJRefreshStateIdle: //普通闲置状态
- {
- [self.loadingView stop];
- //self.loadingView.hidden = YES;
- break;
- }
- case MJRefreshStatePulling: //松开就可以进行刷新的状态
- {
- //self.loadingView.hidden = NO;
- }
- break;
- case MJRefreshStateRefreshing: //正在刷新中的状态
- {
- self.loadingView.animationProgress = 0;
- [self.loadingView play];
- }
- break;
- default:
- break;
- }
- }
- }
- #pragma mark - 实时监听控件 scrollViewContentOffset
- - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change {
- [super scrollViewContentOffsetDidChange:change];
- if(self.jsonString.length > 0) {
- CGPoint point;
- id newVelue = [change valueForKey:NSKeyValueChangeNewKey];
- [(NSValue *)newVelue getValue:&point];
-
- //id newVelue1 = [change objectForKey:NSKeyValueChangeNewKey];
- //CGPoint point1 = ((NSValue *)newVelue1).CGPointValue;//可以取值
-
- //id newVelue2 = [change objectForKey:@"new"];
- //CGPoint point2 = *((__bridge CGPoint *)(newVelue2));//无法取到值
-
- // self.loadingView.hidden = !(self.pullingPercent);
- CGFloat progress = point.y / ([UIScreen mainScreen].bounds.size.height / 3.0);
- if(self.state != MJRefreshStateRefreshing) {
- self.loadingView.animationProgress = -progress;
- }
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|