-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFFRLCollectionViewController.m
More file actions
167 lines (114 loc) · 4.63 KB
/
Copy pathFFRLCollectionViewController.m
File metadata and controls
167 lines (114 loc) · 4.63 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// FFRLCollectionViewController.m
// AppFactory
//
// Created by wujiangwei on 14-9-23.
// Copyright (c) 2014年 Kevin.Wu. All rights reserved.
//
#import "FFRLCollectionViewController.h"
#import "FFLoadMoreFooterView.h"
@interface FFRLCollectionViewController()
<CusRefreshControlDelegate>
@property (nonatomic, strong) FFLoadMoreFooterView *loadMoreFooterView;
@property (nonatomic, assign) BOOL isDataSourceReload;
@end
@implementation FFRLCollectionViewController
@synthesize loadMoreFooterView = _loadMoreFooterView;
- (void)viewDidLoad {
[super viewDidLoad];
self.hasMore = NO;
if (self.aRefreshControl == nil) {
self.aRefreshControl = [[FFDynamicRefreshControl alloc] initWithFrame:CGRectZero];
self.aRefreshControl.frame = CGRectMake(0, 0, self.collectView.frame.size.width, 0);
self.aRefreshControl.delegate = self;
[self.collectView addSubview:self.aRefreshControl];
}
[self.collectView registerClass:[FFLoadMoreFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"kLoadMoreFooterIdentify"];
[self modifyRefreshControlOriginalEdgeInsets];
}
- (void)modifyRefreshControlOriginalEdgeInsets {
[self.aRefreshControl setOriginalEdgeInsets:[self originalContentInset]];
}
- (UIEdgeInsets)originalContentInset {
CGFloat navHeight = ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) ? 64.0 : 0.0;
return UIEdgeInsetsMake(navHeight, 0, 0, 0);
}
#pragma mark -
#pragma mark Property
- (void)setHasMore:(BOOL)hasMore {
if (_hasMore != hasMore && hasMore) {
self.flowLayout.footerReferenceSize = CGSizeMake(self.view.frame.size.width, 44);
}else{
self.flowLayout.footerReferenceSize = CGSizeMake(0, 0);
}
_hasMore = hasMore;
}
#pragma mark -
#pragma mark Public Methods
- (void)setRefreshOriginalEdgeInsets:(UIEdgeInsets)edgeInsets {
[self.aRefreshControl setOriginalEdgeInsets:edgeInsets];
}
- (void)beginReloadData {
}
- (void)endReloadData {
[self doEndReloadData];
// [self performSelector:@selector(doEndReloadData) withObject:nil afterDelay:0.0];
}
- (void)doEndReloadData {
if (self.aRefreshControl != nil) {
self.isDataSourceReload = NO;
[self.aRefreshControl refreshControlScrollViewDataSourceDidFinishedLoading:self.collectView];
}
self.hasMore = NO;
}
#pragma mark -
#pragma mark - collection footer
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if ([kind isEqualToString:UICollectionElementKindSectionFooter] && _hasMore){
UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"kLoadMoreFooterIdentify" forIndexPath:indexPath];
self.loadMoreFooterView = (FFLoadMoreFooterView *)view;
[self.loadMoreFooterView setState:LoadMoreFooterViewStateNormal];
return (UICollectionReusableView *)view;
}
return nil;
}
#pragma mark -
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.collectView) {
if (self.hasMore) {
CGSize aSize = self.collectView.contentSize;
// 加载更多
CGFloat reloadRange = 10.0;
if ((self.collectView.contentOffset.y + CGRectGetHeight(self.collectView.bounds) - self.collectView.contentInset.bottom) > (aSize.height + reloadRange)) {
if (self.loadMoreFooterView && self.loadMoreFooterView.state != LoadMoreFooterViewStateReload) {
self.loadMoreFooterView.state = LoadMoreFooterViewStateReload;
[self reloadViewControllerData];
}
}
}
[self.aRefreshControl refreshControlScrollViewDidScroll:scrollView];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (scrollView == self.collectView) {
[self.aRefreshControl refreshControlScrollViewDidEndDragging:scrollView];
}
}
#pragma mark -
#pragma mark FFDynamicRefreshControlDelegate
- (BOOL)refreshControlDataSourceIsLoading:(FFDynamicRefreshControl *)refreshControl {
return self.isDataSourceReload;
}
- (void)refreshControlDidTriggerRefresh:(FFDynamicRefreshControl *)refreshControl {
self.isDataSourceReload = YES;
[self reloadViewControllerData];
}
#pragma mark -
#pragma mark Override Point
- (void)reloadViewControllerData {
}
- (void)loadMoreViewControllerData {
}
@end