Forráskód Böngészése

fix: (#1400)

1、修复在uicollectionviewcell嵌套tableview使用refresh,在刷新的同时,左右滑动,导致刷新结束以后,无法滚动tableview的情况。经多次测试,动画代理回调,并没有进入animationForKey的判断。猜测是首先响应滚动事件,导致动画已经移除,无法进入判断。从而导致无法重置响应触摸事件以及contentoffset。
2、修复代码,经多次暴利测试。暂时没有发现问题
wendaQueue 5 éve
szülő
commit
4fdeeedb05
1 módosított fájl, 14 hozzáadás és 11 törlés
  1. 14 11
      MJRefresh/Base/MJRefreshHeader.m

+ 14 - 11
MJRefresh/Base/MJRefreshHeader.m

@@ -112,7 +112,6 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
     }
 }
 
-
 - (void)setState:(MJRefreshState)state
 {
     /**
@@ -129,7 +128,6 @@ - (void)setState:(MJRefreshState)state
     // 根据状态做事情
     if (state == MJRefreshStateIdle) {
         if (oldState != MJRefreshStateRefreshing) return;
-        
         // 保存刷新时间
         [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey];
         [[NSUserDefaults standardUserDefaults] synchronize];
@@ -140,7 +138,6 @@ - (void)setState:(MJRefreshState)state
         self.scrollView.mj_insetT += self.insetTDelta;
         // 禁用交互, 如果不禁用可能会引起渲染问题.
         self.scrollView.userInteractionEnabled = NO;
-
         //CAAnimation keyPath 不支持 contentInset 用Bounds的动画代替
         CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
         boundsAnimation.fromValue = [NSValue valueWithCGRect:CGRectOffset(self.scrollView.bounds, 0, self.insetTDelta)];
@@ -150,6 +147,7 @@ - (void)setState:(MJRefreshState)state
         boundsAnimation.fillMode = kCAFillModeBoth;
         boundsAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
         boundsAnimation.delegate = self;
+        [boundsAnimation setValue:MJRefreshHeaderRefreshing2IdleBoundsKey forKey:@"identity"];
 
         [self.scrollView.layer addAnimation:boundsAnimation forKey:MJRefreshHeaderRefreshing2IdleBoundsKey];
         
@@ -183,6 +181,7 @@ - (void)setState:(MJRefreshState)state
             boundsAnimation.duration = MJRefreshFastAnimationDuration;
             //在delegate里移除
             boundsAnimation.removedOnCompletion = NO;
+            [boundsAnimation setValue:MJRefreshHeaderRefreshingBoundsKey forKey:@"identity"];
             boundsAnimation.fillMode = kCAFillModeBoth;
             boundsAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
             boundsAnimation.delegate = self;
@@ -195,29 +194,33 @@ - (void)setState:(MJRefreshState)state
 
 #pragma mark - CAAnimationDelegate
 - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
-    if ([anim isEqual:[self.scrollView.layer animationForKey:MJRefreshHeaderRefreshing2IdleBoundsKey]]) {
-        [self.scrollView.layer removeAnimationForKey:MJRefreshHeaderRefreshing2IdleBoundsKey];
+    NSString *identity = [anim valueForKey:@"identity"];
+    if ([identity isEqualToString:MJRefreshHeaderRefreshing2IdleBoundsKey]) {
         self.pullingPercent = 0.0;
-
         self.scrollView.userInteractionEnabled = YES;
         if (self.endRefreshingCompletionBlock) {
             self.endRefreshingCompletionBlock();
         }
     }
-    
-    if ([anim isEqual:[self.scrollView.layer animationForKey:MJRefreshHeaderRefreshingBoundsKey]]) {
-        [self.scrollView.layer removeAnimationForKey:MJRefreshHeaderRefreshingBoundsKey];
-        
+    if ([identity isEqualToString:MJRefreshHeaderRefreshingBoundsKey]) {
         CGFloat top = self.scrollViewOriginalInset.top + self.mj_h;
         self.scrollView.mj_insetT = top;
         // 设置最终滚动位置
         CGPoint offset = self.scrollView.contentOffset;
         offset.y = -top;
         [self.scrollView setContentOffset:offset animated:NO];
-        
         self.scrollView.userInteractionEnabled = YES;
         [self executeRefreshingCallback];
     }
+    
+    if ([self.scrollView.layer animationForKey:MJRefreshHeaderRefreshing2IdleBoundsKey]) {
+        [self.scrollView.layer removeAnimationForKey:MJRefreshHeaderRefreshing2IdleBoundsKey];
+    }
+    
+    if ([self.scrollView.layer animationForKey:MJRefreshHeaderRefreshingBoundsKey]) {
+        [self.scrollView.layer removeAnimationForKey:MJRefreshHeaderRefreshingBoundsKey];
+        
+    }
 }
 
 #pragma mark - 公共方法