diff --git a/MJRefresh/Base/MJRefreshAutoFooter.h b/MJRefresh/Base/MJRefreshAutoFooter.h index 94a92d0b..3a9b0f37 100644 --- a/MJRefresh/Base/MJRefreshAutoFooter.h +++ b/MJRefresh/Base/MJRefreshAutoFooter.h @@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN /** 是否每一次拖拽只发一次请求 */ @property (assign, nonatomic, getter=isOnlyRefreshPerDrag) BOOL onlyRefreshPerDrag; + +/** 在触发开始刷新前的刷新忽略逻辑, 默认由 isOnlyRefreshPerDrag 和 新手势决定, 用于特殊控制逻辑, 如果不清楚机制, 请勿使用 */ +- (BOOL)ignoreRefreshAction NS_REQUIRES_SUPER; @end NS_ASSUME_NONNULL_END diff --git a/MJRefresh/Base/MJRefreshAutoFooter.m b/MJRefresh/Base/MJRefreshAutoFooter.m index 559bfc4f..61fa73b3 100644 --- a/MJRefresh/Base/MJRefreshAutoFooter.m +++ b/MJRefresh/Base/MJRefreshAutoFooter.m @@ -95,28 +95,46 @@ - (void)scrollViewPanStateDidChange:(NSDictionary *)change if (self.state != MJRefreshStateIdle) return; UIGestureRecognizerState panState = _scrollView.panGestureRecognizer.state; - if (panState == UIGestureRecognizerStateEnded) {// 手松开 - if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕 - if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽 - [self beginRefreshing]; - } - } else { // 超出一个屏幕 - if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) { - [self beginRefreshing]; + + switch (panState) { + // 手松开 + case UIGestureRecognizerStateEnded: { + if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕 + if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽 + [self beginRefreshing]; + } + } else { // 超出一个屏幕 + if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) { + [self beginRefreshing]; + } } + }// ‼️注意: 这里没有 break; fallthrough 执行重置 oneNewPan 语句 (Ended & Canceled & Failed) + + case UIGestureRecognizerStateCancelled: + case UIGestureRecognizerStateFailed: { + self.oneNewPan = NO; + } + break; + + case UIGestureRecognizerStateBegan: { + self.oneNewPan = YES; } - } else if (panState == UIGestureRecognizerStateBegan) { - self.oneNewPan = YES; + break; + + default: + break; } } +- (BOOL)ignoreRefreshAction { + return !self.isOneNewPan && self.isOnlyRefreshPerDrag; +} + - (void)beginRefreshing { - if (!self.isOneNewPan && self.isOnlyRefreshPerDrag) return; + if ([self ignoreRefreshAction]) return; [super beginRefreshing]; - - self.oneNewPan = NO; } - (void)setState:(MJRefreshState)state diff --git a/MJRefresh/Base/MJRefreshComponent.h b/MJRefresh/Base/MJRefreshComponent.h index 88bebe8f..ff0eab42 100644 --- a/MJRefresh/Base/MJRefreshComponent.h +++ b/MJRefresh/Base/MJRefreshComponent.h @@ -73,7 +73,7 @@ typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(void); - (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock; /** 是否正在刷新 */ @property (assign, nonatomic, readonly, getter=isRefreshing) BOOL refreshing; -//- (BOOL)isRefreshing; + /** 刷新状态 一般交给子类内部实现 */ @property (assign, nonatomic) MJRefreshState state; diff --git a/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m b/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m index d16547de..a4be70df 100644 --- a/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m +++ b/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m @@ -15,6 +15,8 @@ @interface MJRefreshAutoStateFooter() } /** 所有状态对应的文字 */ @property (strong, nonatomic) NSMutableDictionary *stateTitles; +/** 用于判断点击 Label 触发特殊的刷新逻辑 */ +@property (assign, nonatomic) BOOL labelIsTrigger; @end @implementation MJRefreshAutoStateFooter @@ -43,11 +45,17 @@ - (void)setTitle:(NSString *)title forState:(MJRefreshState)state self.stateLabel.text = self.stateTitles[@(self.state)]; } +- (BOOL)ignoreRefreshAction { + return !self.labelIsTrigger && [super ignoreRefreshAction]; +} + #pragma mark - 私有方法 - (void)stateLabelClick { if (self.state == MJRefreshStateIdle) { + self.labelIsTrigger = YES; [self beginRefreshing]; + self.labelIsTrigger = NO; } } @@ -89,4 +97,4 @@ - (void)setState:(MJRefreshState)state self.stateLabel.text = self.stateTitles[@(state)]; } } -@end \ No newline at end of file +@end