Skip to content

Commit 9d7e4f9

Browse files
committed
修改bug
1 parent 11c92b2 commit 9d7e4f9

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

YCRefreshControl/YCRefreshManager.m

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ @interface YCRefreshManager ()
4242
{
4343
// scrollView 初始 Inset
4444
UIEdgeInsets _originalInset;
45+
46+
// scrollView 开始拖动的 contentOffset
47+
CGPoint _originalOffset;
4548
}
4649
@property (nonatomic, weak) UIScrollView *scrollView;
4750
@property (nonatomic, weak) UIPanGestureRecognizer *panGestureRecognizer;
@@ -74,6 +77,7 @@ - (instancetype)initWithScrollView:(UIScrollView *)scrollView {
7477
- (void)setupWith:(UIScrollView *)scrollView {
7578
// 首次传入时候,将 _originalInset 设置为 scrollView 的 contentInset
7679
_originalInset = scrollView.contentInset;
80+
_originalOffset = scrollView.contentOffset;
7781

7882
// 将 scrollView 和 scrollView 的滑动手势设置为成员变量
7983
self.scrollView = scrollView;
@@ -87,7 +91,7 @@ - (void)setupWith:(UIScrollView *)scrollView {
8791
}
8892
// 监听属性
8993
- (void)addObserver {
90-
[self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
94+
[self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
9195
[self.scrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil];
9296
[self.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
9397
[self.scrollView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
@@ -177,7 +181,7 @@ - (void)handleRefreshViewChange:(NSDictionary *)change {
177181
- (void)handleContentOffsetChange:(NSDictionary *)change {
178182
// scrollview 当前滑动到的位置,去掉 contentInset 的影响
179183
CGFloat offsetY = _scrollView.contentOffset.y + _scrollView.contentInset.top;
180-
if (offsetY < 0) {
184+
if (offsetY < 0 && _loadmoreState != YCLoadmoreStateNoData && _loadmoreState != YCLoadmoreStateLoading) {
181185
// 如果设置了 refreshAction ,并且现在不处于刷新状态才继续进行
182186
if (self.refreshAction && _refreshState != YCRefreshStateRefreshing && _refreshState != YCRefreshStateRefreshed) {
183187

@@ -200,12 +204,13 @@ - (void)handleContentOffsetChange:(NSDictionary *)change {
200204
}
201205
}
202206

203-
if (self.loadmoreAction) {
207+
if (self.loadmoreAction && _refreshState != YCRefreshStateRefreshing && _refreshState != YCRefreshStateRefreshed) {
204208
CGFloat boundHeight = _scrollView.bounds.size.height;
205209
CGFloat contentHeight = _scrollView.contentSize.height;
206210
offsetY = contentHeight - boundHeight - _scrollView.contentOffset.y + _scrollView.contentInset.bottom;
207211

208-
if (contentHeight > 0) {
212+
NSValue *newValue = [change objectForKey:@"new"];
213+
if (_scrollView.isTracking && contentHeight > 0 && [newValue CGPointValue].y > _originalOffset.y) {
209214
if (_loadmoreState != YCLoadmoreStateNoData && _loadmoreState != YCLoadmoreStateLoading) {
210215
if (offsetY >= [_scrollView.yc_loadmoreView loadmoreHeight]) {
211216
_loadmoreState = YCLoadmoreStatePulling;
@@ -258,10 +263,8 @@ - (void)setScrollContent {
258263
}else if(_refreshState == YCRefreshStateRefreshed) {
259264
// 重置 scrollView 的 contentInset 到原始数值
260265
[self resetScrollViewContentInsetWithCompletion:^(BOOL finished) {
261-
if (finished) {
262-
// 说明已经执行过 endRefresh 将 refreshState 重置
263-
_refreshState = YCRefreshStateNormal;
264-
}
266+
// 说明已经执行过 endRefresh 将 refreshState 重置
267+
_refreshState = YCRefreshStateNormal;
265268
}];
266269
}
267270
}
@@ -271,17 +274,15 @@ - (void)setScrollContent {
271274
[self setScrollViewContentInsetForRefreshingAnimated:YES];
272275
}else if(_refreshState == YCRefreshStateRefreshed) {
273276
[self resetScrollViewContentInsetWithCompletion:^(BOOL finished) {
274-
if (finished) {
275-
// 说明已经执行过 endRefresh 将 refreshState 重置
276-
_refreshState = YCRefreshStateNormal;
277-
}
277+
// 说明已经执行过 endRefresh 将 refreshState 重置
278+
_refreshState = YCRefreshStateNormal;
278279
}];
279280
}
280281

281282
}
282283
// 手势开始触发
283284
else if (self.panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
284-
285+
_originalOffset = _scrollView.contentOffset;
285286
}
286287
}
287288
- (void)tapLoadmoreView {

YCRefreshControl/YCSlimeRefreshView.m

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,17 @@ - (void)endAnimation {
292292
_tipLabel.alpha = 0.5;
293293
_activity.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
294294
} completion:^(BOOL finished) {
295-
if (finished) {
296-
_tipLabel.alpha = 0;
297-
[_activity stopAnimating];
298-
[_shapeLayer removeAllAnimations];
299-
_shapeLayer.path = nil;
300-
_shapeLayer.shadowPath = nil;
301-
_shapeLayer.position = CGPointZero;
302-
[_arrowLayer removeAllAnimations];
303-
_arrowLayer.path = nil;
304-
[_highlightLayer removeAllAnimations];
305-
_highlightLayer.path = nil;
306-
_refreshing = NO;
307-
}
295+
_tipLabel.alpha = 0;
296+
[_activity stopAnimating];
297+
[_shapeLayer removeAllAnimations];
298+
_shapeLayer.path = nil;
299+
_shapeLayer.shadowPath = nil;
300+
_shapeLayer.position = CGPointZero;
301+
[_arrowLayer removeAllAnimations];
302+
_arrowLayer.path = nil;
303+
[_highlightLayer removeAllAnimations];
304+
_highlightLayer.path = nil;
305+
_refreshing = NO;
308306
}];
309307
}
310308
}

0 commit comments

Comments
 (0)