|
@@ -15,6 +15,7 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
@property (nonatomic,strong) NSMutableDictionary *stateTitle;
|
|
@property (nonatomic,strong) NSMutableDictionary *stateTitle;
|
|
|
@property (nonatomic,strong) UILabel *refreshTitleLabel;
|
|
@property (nonatomic,strong) UILabel *refreshTitleLabel;
|
|
|
@property (nonatomic,assign) BOOL stopWithNomore;
|
|
@property (nonatomic,assign) BOOL stopWithNomore;
|
|
|
|
|
+@property (nonatomic,assign) BOOL autoRefresh;
|
|
|
|
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
@@ -49,7 +50,7 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
if (!_stateTitle) {
|
|
if (!_stateTitle) {
|
|
|
_stateTitle = [@{
|
|
_stateTitle = [@{
|
|
|
@(JLRefreshStateIdle) : @"pull to load more",
|
|
@(JLRefreshStateIdle) : @"pull to load more",
|
|
|
- @(JLRefreshStatePulling) : @"pull to load more",
|
|
|
|
|
|
|
+ @(JLRefreshStatePulling) : @"will load more",
|
|
|
@(JLRefreshStateWillRefresh) : @"loosen to load more",
|
|
@(JLRefreshStateWillRefresh) : @"loosen to load more",
|
|
|
@(JLRefreshStateRefreshing) : @"loading...",
|
|
@(JLRefreshStateRefreshing) : @"loading...",
|
|
|
@(JLRefreshStateNoMore) : @"no more"
|
|
@(JLRefreshStateNoMore) : @"no more"
|
|
@@ -145,8 +146,11 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- if (self.scrollView.isDragging) {
|
|
|
|
|
|
|
+ // autoRefresh 修复拖拽松手后,减速完成触底时状态WillRefresh改变Idle,界面闪一下。
|
|
|
|
|
+ if (self.scrollView.isDragging && self.autoRefresh) {
|
|
|
|
|
+
|
|
|
|
|
+// NSLog(@"%d -> %d",0,self.state);
|
|
|
|
|
+
|
|
|
if (self.state == JLRefreshStateNoMore) {
|
|
if (self.state == JLRefreshStateNoMore) {
|
|
|
|
|
|
|
|
self.state = JLRefreshStateIdle;
|
|
self.state = JLRefreshStateIdle;
|
|
@@ -168,11 +172,9 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
-
|
|
|
|
|
- // 停止拖动的减速过程
|
|
|
|
|
- if (self.state != JLRefreshStateRefreshing && offsetY >= idle2WillRefresh) {
|
|
|
|
|
- self.state = JLRefreshStateRefreshing;
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+// NSLog(@"%d -> %d",1,self.state);
|
|
|
|
|
+
|
|
|
|
|
+ if (self.state != JLRefreshStateRefreshing) {
|
|
|
if (self.stopWithNomore) {
|
|
if (self.stopWithNomore) {
|
|
|
[self setState:JLRefreshStateNoMore];
|
|
[self setState:JLRefreshStateNoMore];
|
|
|
}
|
|
}
|
|
@@ -180,7 +182,7 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
self.state = JLRefreshStateIdle;
|
|
self.state = JLRefreshStateIdle;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
float percentage = (offsetY - startY) / self.jl_height;
|
|
float percentage = (offsetY - startY) / self.jl_height;
|
|
@@ -199,6 +201,7 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
|
|
|
|
|
CGPoint old = [change[@"old"] CGPointValue];
|
|
CGPoint old = [change[@"old"] CGPointValue];
|
|
|
CGPoint new = [change[@"new"] CGPointValue];
|
|
CGPoint new = [change[@"new"] CGPointValue];
|
|
|
|
|
+// NSLog(@"%d -> %d",2,self.state);
|
|
|
|
|
|
|
|
if (self.scrollView.jl_insetTop == self.scrollViewOriginInsetTop && new.y > -self.scrollViewOriginInsetTop && old.y < new.y) { // 上拉,在未超出height的范围内拖动都视为刷新
|
|
if (self.scrollView.jl_insetTop == self.scrollViewOriginInsetTop && new.y > -self.scrollViewOriginInsetTop && old.y < new.y) { // 上拉,在未超出height的范围内拖动都视为刷新
|
|
|
|
|
|
|
@@ -226,14 +229,18 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
- (void)scrollViewPanGestureStateDidChange:(NSDictionary<NSKeyValueChangeKey,id> *)change {
|
|
- (void)scrollViewPanGestureStateDidChange:(NSDictionary<NSKeyValueChangeKey,id> *)change {
|
|
|
|
|
|
|
|
[super scrollViewPanGestureStateDidChange:change];
|
|
[super scrollViewPanGestureStateDidChange:change];
|
|
|
|
|
+// NSLog(@"%d -> %d",3,self.state);
|
|
|
|
|
|
|
|
|
|
+ if (self.pan.state == UIGestureRecognizerStateBegan) {
|
|
|
|
|
+ self.autoRefresh = YES;
|
|
|
|
|
+ }
|
|
|
if (self.pan.state == UIGestureRecognizerStateEnded) {
|
|
if (self.pan.state == UIGestureRecognizerStateEnded) {
|
|
|
|
|
|
|
|
if (self.state == JLRefreshStateWillRefresh) {
|
|
if (self.state == JLRefreshStateWillRefresh) {
|
|
|
self.state = JLRefreshStateRefreshing;
|
|
self.state = JLRefreshStateRefreshing;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.autoRefresh = NO;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -244,14 +251,14 @@ CGFloat const JLRefreshFooterHeight = 30;
|
|
|
|
|
|
|
|
JLRefreshState oldState = self.state;
|
|
JLRefreshState oldState = self.state;
|
|
|
|
|
|
|
|
- if (state == oldState) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (self.stateChangeBlock) {
|
|
if (self.stateChangeBlock) {
|
|
|
self.stateChangeBlock(state);
|
|
self.stateChangeBlock(state);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (state == oldState) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
super.state = state;
|
|
super.state = state;
|
|
|
|
|
|
|
|
__weak typeof(self) weakself = self;
|
|
__weak typeof(self) weakself = self;
|