Skip to content

header刷新不回弹的问题 #1292

Closed

Description

@Parker-zhu

1.header刷新不回弹的问题
复现代码:[table.mj_header beginRefreshing];
[table.mj_footer endRefreshing];
一起使用就会毕现,当然一般人不会这么用,只是举个例子说明问题
MJRefreshHeader中setState方法
`- (void)setState:(MJRefreshState)state
{
MJRefreshCheckState

// 根据状态做事情
if (state == MJRefreshStateIdle) {
    NSLog(@"2");
    if (oldState != MJRefreshStateRefreshing) return;
    
    // 保存刷新时间
    [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    // 恢复inset和offset
    [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{
        self.scrollView.mj_insetT += self.insetTDelta;
        
        // 自动调整透明度
        if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0;
    } completion:^(BOOL finished) {
        self.pullingPercent = 0.0;
        
        if (self.endRefreshingCompletionBlock) {
            self.endRefreshingCompletionBlock();
        }
    }];
} else if (state == MJRefreshStateRefreshing) {
    MJRefreshDispatchAsyncOnMainQueue({
        NSLog(@"1");
        [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
            if (self.scrollView.panGestureRecognizer.state != UIGestureRecognizerStateCancelled) {
                CGFloat top = self.scrollViewOriginalInset.top + self.mj_h;
                // 增加滚动区域top
                self.scrollView.mj_insetT = top;
                // 设置滚动位置
                CGPoint offset = self.scrollView.contentOffset;
                offset.y = -top;
                [self.scrollView setContentOffset:offset animated:NO];
            }
        } completion:^(BOOL finished) {
            [self executeRefreshingCallback];
        }];
    })
}

}`
打印结果:2,1
从代码中也可以发现state == MJRefreshStateRefreshing时加了这一句MJRefreshDispatchAsyncOnMainQueue

Activity

  1. Parker-zhu commented on May 16, 2019

    @Parker-zhu
    Author

    [table.mj_header beginRefreshing];
    [table.mj_header endRefreshing];
    都是header,上面写错了

  2. wolfcon commented on May 16, 2019

    @wolfcon
    Collaborator

    现阶段的 State 状态机 有缺陷, 的确在这样的特殊误用情况下会产生问题

    原因是: 状态机中某些操作时依赖 DispatchQueue 的异步分发, 导致有微延迟, 而某些改变状态时又未使用异步分发

    在修复之前, 非要误用的话, 这样使用先

    tableView.mj_header.beginRefreshing()
    DispatchQueue.main.async {
        self.tableView.mj_header.endRefreshing()
    }
  3. wolfcon commented on May 16, 2019

    @wolfcon
    Collaborator
  4. corderguo commented on May 22, 2019

    @corderguo

    的确有这个bug,而且下次刷新也不会恢复,建议下次刷新的时候可以自动恢复

  5. added 2 commits that reference this issue on Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions