Explorar el Código

Fix automaticallyHidden bug, thanks for f33chobits's advice

Fix automaticallyHidden bug, thanks for f33chobits's advice
MJLee hace 10 años
padre
commit
56d60959ce

+ 1 - 1
MJRefresh.podspec

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

+ 8 - 3
MJRefresh/Base/MJRefreshComponent.m

@@ -104,12 +104,17 @@ - (void)removeObservers
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
     // 遇到这些情况就直接返回
-    if (!self.userInteractionEnabled || self.hidden) return;
+    if (!self.userInteractionEnabled) return;
     
+    // 这个就算看不见也需要处理
+    if ([keyPath isEqualToString:MJRefreshKeyPathContentSize]) {
+        [self scrollViewContentSizeDidChange:change];
+    }
+    
+    // 看不见
+    if (self.hidden || self.alpha <= 0.01) return;
     if ([keyPath isEqualToString:MJRefreshKeyPathContentOffset]) {
         [self scrollViewContentOffsetDidChange:change];
-    } else if ([keyPath isEqualToString:MJRefreshKeyPathContentSize]) {
-        [self scrollViewContentSizeDidChange:change];
     } else if ([keyPath isEqualToString:MJRefreshKeyPathPanState]) {
         [self scrollViewPanStateDidChange:change];
     }

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


+ 22 - 3
MJRefreshExample/MJRefreshExample/Classes/MJTableViewController.m

@@ -133,6 +133,8 @@ - (void)example06
 #pragma mark UITableView + 上拉刷新 默认
 - (void)example11
 {
+    [self example01];
+    
     __weak __typeof(self) weakSelf = self;
     
     // 设置回调(一旦进入刷新状态就会调用这个refreshingBlock)
@@ -144,6 +146,8 @@ - (void)example11
 #pragma mark UITableView + 上拉刷新 动画图片
 - (void)example12
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     self.tableView.footer = [MJChiBaoZiFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
 }
@@ -151,6 +155,8 @@ - (void)example12
 #pragma mark UITableView + 上拉刷新 隐藏刷新状态的文字
 - (void)example13
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     MJChiBaoZiFooter *footer = [MJChiBaoZiFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
     
@@ -167,6 +173,8 @@ - (void)example13
 #pragma mark UITableView + 上拉刷新 全部加载完毕
 - (void)example14
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadLastData方法)
     self.tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadLastData)];
     
@@ -184,6 +192,8 @@ - (void)reset
 #pragma mark UITableView + 上拉刷新 禁止自动加载
 - (void)example15
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
     
@@ -197,6 +207,8 @@ - (void)example15
 #pragma mark UITableView + 上拉刷新 自定义文字
 - (void)example16
 {
+    [self example01];
+    
     // 添加默认的上拉刷新
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
@@ -219,6 +231,8 @@ - (void)example16
 #pragma mark UITableView + 上拉刷新 加载后隐藏
 - (void)example17
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadOnceData方法)
     self.tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadOnceData)];
 }
@@ -226,6 +240,8 @@ - (void)example17
 #pragma mark UITableView + 上拉刷新 自动回弹的上拉01
 - (void)example18
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     self.tableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
     // 设置了底部inset
@@ -237,6 +253,8 @@ - (void)example18
 #pragma mark UITableView + 上拉刷新 自动回弹的上拉02
 - (void)example19
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadLastData方法)
     self.tableView.footer = [MJChiBaoZiFooter2 footerWithRefreshingTarget:self refreshingAction:@selector(loadLastData)];
     self.tableView.footer.automaticallyChangeAlpha = YES;
@@ -245,6 +263,8 @@ - (void)example19
 #pragma mark UITableView + 上拉刷新 自定义刷新控件(自动刷新)
 - (void)example20
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     self.tableView.footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
 }
@@ -252,6 +272,8 @@ - (void)example20
 #pragma mark UITableView + 上拉刷新 自定义刷新控件(自动回弹)
 - (void)example21
 {
+    [self example01];
+    
     // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
     self.tableView.footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
 }
@@ -333,9 +355,6 @@ - (NSMutableArray *)data
 {
     if (!_data) {
         self.data = [NSMutableArray array];
-        for (int i = 0; i<5; i++) {
-            [self.data addObject:MJRandomData];
-        }
     }
     return _data;
 }