Sfoglia il codice sorgente

A lot of modification

A lot of modification
MJLee 10 anni fa
parent
commit
91a8485271

+ 1 - 1
MJRefresh.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
   s.name         = "MJRefresh"
-  s.version      = "2.4.0"
+  s.version      = "2.4.1"
   s.summary      = "The easiest way to use pull-to-refresh"
   s.homepage     = "https://github.com/CoderMJLee/MJRefresh"
   s.license      = "MIT"

+ 2 - 2
MJRefresh/Base/MJRefreshAutoFooter.h

@@ -15,6 +15,6 @@
 /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
 @property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh;
 
-/** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏) */
-@property (assign, nonatomic) BOOL automaticallyHidden;
+/** 防止加载数据速度过快时,连续刷新N次 */
+@property (assign, nonatomic, getter=isPreventContinuousRefreshing) BOOL preventContinuousRefreshing;
 @end

+ 8 - 22
MJRefresh/Base/MJRefreshAutoFooter.m

@@ -50,24 +50,6 @@ - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
     
     // 设置位置
     self.mj_y = _scrollView.mj_contentH;
-    
-    if ([self.scrollView isKindOfClass:[UITableView class]]) {
-        UITableView *tableView = (UITableView *)self.scrollView;
-        NSInteger count = 0;
-        NSInteger sections = [tableView numberOfSections];
-        for (NSInteger i = 0; i < sections; i++) {
-            count += [tableView numberOfRowsInSection:i];
-        }
-        self.hidden = (count == 0);
-    } else if ([self.scrollView isKindOfClass:[UICollectionView class]]) {
-        UICollectionView *collectionView = (UICollectionView *)self.scrollView;
-        NSInteger count = 0;
-        NSInteger sections = [collectionView numberOfSections];
-        for (NSInteger i = 0; i < sections; i++) {
-            count += [collectionView numberOfItemsInSection:i];
-        }
-        self.hidden = (count == 0);
-    }
 }
 
 - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
@@ -86,6 +68,13 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
             
             // 当底部刷新控件完全出现时,才刷新
             [self beginRefreshing];
+            
+            // 如果正在减速,并且希望阻止连续刷新
+            if (self.scrollView.isDecelerating && self.preventContinuousRefreshing) {
+                CGPoint offset = self.scrollView.contentOffset;
+                offset.y = _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h + _scrollView.mj_insetB - self.mj_h;
+                [self.scrollView setContentOffset:offset animated:YES];
+            }
         }
     }
 }
@@ -114,10 +103,7 @@ - (void)setState:(MJRefreshState)state
     MJRefreshCheckState
     
     if (state == MJRefreshStateRefreshing) {
-        // 这里延迟是防止惯性导致连续上拉
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-            [self executeRefreshingCallback];
-        });
+        [self executeRefreshingCallback];
     }
 }
 

+ 2 - 2
MJRefresh/Base/MJRefreshBackFooter.m

@@ -65,9 +65,9 @@ - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
     [super scrollViewContentSizeDidChange:change];
     
     // 内容的高度
-    CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetTop;
+    CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom;
     // 表格的高度
-    CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetTop;
+    CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom;
     // 这里一定是用:self.scrollView.mj_insetT 和 self.scrollViewOriginalInset.bottom;
     // 设置位置和尺寸
     self.mj_y = MAX(contentHeight, scrollHeight);

+ 4 - 1
MJRefresh/Base/MJRefreshFooter.h

@@ -21,5 +21,8 @@
 - (void)resetNoMoreData;
 
 /** 忽略多少scrollView的contentInset的bottom */
-@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop;
+@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom;
+
+/** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏) */
+@property (assign, nonatomic) BOOL automaticallyHidden;
 @end

+ 24 - 0
MJRefresh/Base/MJRefreshFooter.m

@@ -37,6 +37,30 @@ - (void)prepare
     self.mj_h = MJRefreshFooterHeight;
 }
 
+
+- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
+{
+    [super scrollViewContentSizeDidChange:change];
+    
+    if ([self.scrollView isKindOfClass:[UITableView class]]) {
+        UITableView *tableView = (UITableView *)self.scrollView;
+        NSInteger count = 0;
+        NSInteger sections = [tableView numberOfSections];
+        for (NSInteger i = 0; i < sections; i++) {
+            count += [tableView numberOfRowsInSection:i];
+        }
+        self.hidden = (count == 0);
+    } else if ([self.scrollView isKindOfClass:[UICollectionView class]]) {
+        UICollectionView *collectionView = (UICollectionView *)self.scrollView;
+        NSInteger count = 0;
+        NSInteger sections = [collectionView numberOfSections];
+        for (NSInteger i = 0; i < sections; i++) {
+            count += [collectionView numberOfItemsInSection:i];
+        }
+        self.hidden = (count == 0);
+    }
+}
+
 #pragma mark - 公共方法
 - (void)noticeNoMoreData
 {

BIN
MJRefreshExample/MJRefreshExample.xcodeproj/project.xcworkspace/xcuserdata/mj.xcuserdatad/UserInterfaceState.xcuserstate


+ 1 - 1
MJRefreshExample/MJRefreshExample/Classes/MJTableViewController.m

@@ -231,7 +231,7 @@ - (void)example18
     // 设置了底部inset
     self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 30, 0);
     // 忽略掉底部inset
-    self.tableView.footer.ignoredScrollViewContentInsetTop = 30;
+    self.tableView.footer.ignoredScrollViewContentInsetBottom = 30;
 }
 
 #pragma mark UITableView + 上拉刷新 自动回弹的上拉02

+ 76 - 0
README.md

@@ -9,6 +9,11 @@
     * [Installation【如何使用MJRefresh】](#如何使用MJRefresh)
     * [Who's using【已经超过上百个App正在使用MJRefresh】](#已经超过上百个App正在使用MJRefresh)
     * [Classes【MJRefresh类结构图】](#MJRefresh类结构图)
+* 常见API
+	* [MJRefreshComponent.h](#MJRefreshComponent.h)
+	* [MJRefreshHeader.h](#MJRefreshHeader.h)
+	* [MJRefreshFooter.h](#MJRefreshFooter.h)
+	* [MJRefreshAutoFooter.h](#MJRefreshAutoFooter.h)
 * Examples
     * [Reference【参考】](#参考)
     * [下拉刷新01-默认](#下拉刷新01-默认)
@@ -70,6 +75,77 @@ UIView+MJExtension.h        UIView+MJExtension.m
 - 关于如何自定义刷新控件,可以参考下图的类<br>
 <img src="http://images0.cnblogs.com/blog2015/497279/201506/141358159107893.png" width="30%" height="30%">
 
+## <a id="MJRefreshComponent.h"></a>MJRefreshComponent.h
+```objc
+/** 刷新控件的基类 */
+@interface MJRefreshComponent : UIView
+#pragma mark - 刷新状态控制
+/** 进入刷新状态 */
+- (void)beginRefreshing;
+/** 结束刷新状态 */
+- (void)endRefreshing;
+/** 是否正在刷新 */
+- (BOOL)isRefreshing;
+
+#pragma mark - 其他
+/** 根据拖拽比例自动切换透明度 */
+@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
+@end
+```
+
+## <a id="MJRefreshHeader.h"></a>MJRefreshHeader.h
+```objc
+@interface MJRefreshHeader : MJRefreshComponent
+/** 创建header */
++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
+/** 创建header */
++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
+
+/** 这个key用来存储上一次下拉刷新成功的时间 */
+@property (copy, nonatomic) NSString *lastUpdatedTimeKey;
+/** 上一次下拉刷新成功的时间 */
+@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime;
+
+/** 忽略多少scrollView的contentInset的top */
+@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop;
+@end
+```
+
+## <a id="MJRefreshFooter.h"></a>MJRefreshFooter.h
+```objc
+@interface MJRefreshFooter : MJRefreshComponent
+/** 创建footer */
++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
+/** 创建footer */
++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
+
+/** 提示没有更多的数据 */
+- (void)noticeNoMoreData;
+/** 重置没有更多的数据(消除没有更多数据的状态) */
+- (void)resetNoMoreData;
+
+/** 忽略多少scrollView的contentInset的bottom */
+@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom;
+
+/** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏) */
+@property (assign, nonatomic) BOOL automaticallyHidden;
+@end
+```
+
+## <a id="MJRefreshAutoFooter.h"></a>MJRefreshAutoFooter.h
+```objc
+@interface MJRefreshAutoFooter : MJRefreshFooter
+/** 是否自动刷新(默认为YES) */
+@property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
+
+/** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
+@property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh;
+
+/** 防止加载数据速度过快时,连续刷新N次 */
+@property (assign, nonatomic, getter=isPreventContinuousRefreshing) BOOL preventContinuousRefreshing;
+@end
+```
+
 ## <a id="参考"></a>参考
 ```objc
 * 由于这个框架的功能较多,就不写具体文字描述其用法