MJRefresh icon indicating copy to clipboard operation
MJRefresh copied to clipboard

高度计算延迟的bug-上拉刷新动态添加一个数据很明显

Open RbBtSn0w opened this issue 9 years ago • 2 comments

KVO 更新位置的时候

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

如果通过

[self.tableView beginUpdates];
 [self.tableView insertRowsAtIndexPaths:insertRowsAtIndexPaths withRowAnimation:UITableViewRowAnimationBottom];
 [self.tableView endUpdates];

这样的方式更新,新加入的cell的出现在tablview 上的时候, 完成更新footer的操作:

- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
    [super scrollViewContentSizeDidChange:change];
    
    // 设置位置
    self.mj_y = self.scrollView.mj_contentH;
}

实际上是滞后的。

现象就是,先看到新的cell 加载出来,这个时候footer 会停在当前的位置,直到收到KVO的通知,才更新footer 的位置。

RbBtSn0w avatar Dec 06 '16 14:12 RbBtSn0w

的确存在这个问题

wolfcon avatar Jun 27 '19 09:06 wolfcon

这个问题与 CollectionView 系统自带的 FlowLayout 加载时的动画冲突机制类似, 都是 View 本身的动画与 Refresh 的动画造成的冲突.

wolfcon avatar Sep 17 '21 02:09 wolfcon