-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMJRefreshBaseView.h
104 lines (90 loc) · 2.82 KB
/
MJRefreshBaseView.h
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
//
// MJRefreshBaseView.h
// MJRefresh
//
// Created by mj on 13-3-4.
// Copyright (c) 2013年 itcast. All rights reserved.
#import <UIKit/UIKit.h>
/**
枚举
*/
// 控件的刷新状态
typedef enum {
MJRefreshStatePulling = 1, // 松开就可以进行刷新的状态
MJRefreshStateNormal = 2, // 普通状态
MJRefreshStateRefreshing = 3, // 正在刷新中的状态
MJRefreshStateWillRefreshing = 4
} MJRefreshState;
// 控件的类型
typedef enum {
MJRefreshViewTypeHeader = -1, // 头部控件
MJRefreshViewTypeFooter = 1 // 尾部控件
} MJRefreshViewType;
@class MJRefreshBaseView;
/**
回调的Block定义
*/
// 开始进入刷新状态就会调用
typedef void (^BeginRefreshingBlock)(MJRefreshBaseView *refreshView);
// 刷新完毕就会调用
typedef void (^EndRefreshingBlock)(MJRefreshBaseView *refreshView);
// 刷新状态变更就会调用
typedef void (^RefreshStateChangeBlock)(MJRefreshBaseView *refreshView, MJRefreshState state);
/**
代理的协议定义
*/
@protocol MJRefreshBaseViewDelegate <NSObject>
@optional
// 开始进入刷新状态就会调用
- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView;
// 刷新完毕就会调用
- (void)refreshViewEndRefreshing:(MJRefreshBaseView *)refreshView;
// 刷新状态变更就会调用
- (void)refreshView:(MJRefreshBaseView *)refreshView stateChange:(MJRefreshState)state;
@end
/**
类的声明
*/
@interface MJRefreshBaseView : UIView
{
// 父控件一开始的contentInset
UIEdgeInsets _scrollViewInitInset;
// 父控件
__weak UIScrollView *_scrollView;
// 子控件
__weak UILabel *_lastUpdateTimeLabel;
__weak UILabel *_statusLabel;
__weak UIImageView *_arrowImage;
__weak UIActivityIndicatorView *_activityView;
// 状态
MJRefreshState _state;
}
// 构造方法
- (instancetype)initWithScrollView:(UIScrollView *)scrollView;
// 设置要显示的父控件
@property (nonatomic, weak) UIScrollView *scrollView;
// 内部的控件
@property (nonatomic, weak, readonly) UILabel *lastUpdateTimeLabel;
@property (nonatomic, weak, readonly) UILabel *statusLabel;
@property (nonatomic, weak, readonly) UIImageView *arrowImage;
// Block回调
@property (nonatomic, copy) BeginRefreshingBlock beginRefreshingBlock;
@property (nonatomic, copy) RefreshStateChangeBlock refreshStateChangeBlock;
@property (nonatomic, copy) EndRefreshingBlock endStateChangeBlock;
// 代理
@property (nonatomic, weak) id<MJRefreshBaseViewDelegate> delegate;
// 是否正在刷新
@property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing;
// 开始刷新
- (void)beginRefreshing;
// 结束刷新
- (void)endRefreshing;
// 不静止地结束刷新
- (void)endRefreshingWithoutIdle;
// 结束使用、释放资源
- (void)free;
/**
交给子类去实现 和 调用
*/
- (void)setState:(MJRefreshState)state;
@end