JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
//  Copyright © 2015年 dahua. All rights reserved.
//
 
#import "LCRefreshHeader.h"
#import <LCBaseModule/DHActivityIndicatorView.h>
 
@interface LCRefreshHeader ()
{
    DHActivityIndicatorView *actionView;
    UILabel *statelabel;
}
@end
 
@implementation LCRefreshHeader
#pragma mark - 重写方法
#pragma mark 在这里做一些初始化配置(比如添加子控件)
- (void)prepare
{
    [super prepare];
    
 
    self.pullString = @"mobile_common_pull_down_to_refresh".lc_T;
    self.releaseString = @"mobile_common_data_loading".lc_T;
    self.refreshString = @"mobile_common_data_loading".lc_T;
    
    statelabel = [[UILabel alloc]initWithFrame:CGRectZero];
    statelabel.font = MJRefreshLabelFont;
    statelabel.textColor = MJRefreshLabelTextColor;
    statelabel.textAlignment = NSTextAlignmentCenter;
    statelabel.backgroundColor = [UIColor clearColor];
    [statelabel setNumberOfLines:0];
    
    actionView = [[DHActivityIndicatorView alloc]init];
    [self addSubview:statelabel];
    [self addSubview:actionView];
}
 
#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews
{
    [super placeSubviews];
 
    statelabel.frame = CGRectMake(0,0, self.frame.size.width , self.frame.size.height);
    statelabel.hidden = _hideTips;
    
    if (_hideTips) {
        actionView.frame = CGRectMake((self.frame.size.width - 22) / 2 , (self.frame.size.height - 22) / 2, 22, 22);
    } else {
        actionView.frame = CGRectMake(self.frame.size.width / 2 - 100, (self.frame.size.height - 22) / 2, 22, 22);
    }
}
 
#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
    [super scrollViewContentOffsetDidChange:change];
    CGFloat angle = M_PI * self.scrollView.contentOffset.y / MJRefreshHeaderHeight ;
    actionView.rotationView.transform = CGAffineTransformMakeRotation(angle);
    actionView.backgroundView.transform = CGAffineTransformMakeRotation(-angle);
}
 
#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
    [super scrollViewContentSizeDidChange:change];
}
 
#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
    [super scrollViewPanStateDidChange:change];
    
}
 
 
#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState;
    
    switch (state) {
        case MJRefreshStateIdle:
             [actionView stopAnimating];
            statelabel.text = self.pullString;
            break;
        case MJRefreshStatePulling:
            
            statelabel.text = self.releaseString;
            break;
        case MJRefreshStateRefreshing:
            statelabel.text = self.refreshString;
            [actionView startAnimating];
            break;
        default:
            break;
    }
}
#pragma mark 监听拖拽比例(控件被拖出来的比例)
- (void)setPullingPercent:(CGFloat)pullingPercent
{
    [super setPullingPercent:pullingPercent];
}
 
@end