Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

和sticky header(头部固定)的UICollectionView混用的时候,下拉刷新出现奇怪的动画效果 #225

Closed
kyfxbl opened this issue Jul 17, 2015 · 5 comments

Comments

@kyfxbl
Copy link

kyfxbl commented Jul 17, 2015

我故意把动画的时间从MJRefreshFastAnimationDuration改成3秒,为了看得更清楚。在默认的动画时间下,不会这么明显,但是也有明显的一闪,显得很奇怪

animation_bug

读了一下代码,最后定位到这一段:

[UIView animateWithDuration:3 animations:^{
            // 增加滚动区域
            CGFloat top = self.scrollViewOriginalInset.top + self.mj_h;
            self.scrollView.mj_insetT = top;

            // 设置滚动位置
            self.scrollView.mj_offsetY = - top;
        } completion:^(BOOL finished) {
            [self executeRefreshingCallback];
        }];

似乎是因为修改contentInset引起的,好像UICollectionView的隐式动画和这里的显式动画有冲突,但也不确定。可否提供一点思路,这个现象可能是由什么原因引起的?谢谢!

@CoderMJLee
Copy link
Owner

好的,我抽空看看哈

@zymxxxs
Copy link

zymxxxs commented Mar 16, 2016

Mj,我也遇到了这个问题,我在使用CSStickyHeaderFlowLayout之后,上下拉刷新都会出现headerView浮动的情况,我尝试着把开始刷新以及结束刷新的动画代码屏蔽之后,该现象倒是没有了,跟人感觉并不应该这么解决。不知道是CSStickyHeaderFlowLayout的问题还是怎样,麻烦你看一下吧。

@ShannonChenCHN
Copy link

ShannonChenCHN commented Aug 27, 2016

将动画引擎由 Apple 的 Core Animation 改为 facebook 的 Pop 之后,貌似没有问题了。->_->PR:737

@ShannonChenCHN
Copy link

ShannonChenCHN commented Aug 26, 2017

@zymxxx 可以试试在下拉刷新时让 sticky header(头部固定)的 UICollectionViewLayout 的那几个自定义布局的方法返回默认值:

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
    
    NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];
    
    // https://github.com/CoderMJLee/MJRefresh/issues/225#issuecomment-325103061
    if (self.enabled == NO) {
        return originalAttributes;
    }
    ...
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
    if (self.enabled == NO) {
        return [super shouldInvalidateLayoutForBoundsChange:newBounds];
    }
    
    return YES;
}

-------------------------- Update ---------------------
上面的方法也不行,后来我试了一下在 -reloadData 之后,做个延时再去 endRefreshing 操作,避免UICollectionView 的更新和 UIView 动画发生冲突,截止目前,上述问题就再没有复现过了:

[self.collectionView reloadData];
// https://github.com/CoderMJLee/MJRefresh/issues/225#issuecomment-325103061
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
     [self.collectionView.mj_header endRefreshing];
});

@RisingSSR
Copy link

Simulator.Screen.Recording.-.iPhone.14.Pro.Max.-.2023-09-15.at.16.37.29.mp4

我继承 UICollectionViewLayout 自定义了一个layout,在实现的时候出现了上述情况

      let header = MJRefreshGifHeader {
          // self.mappy.clean()
          // self.request(sno: "2021215154")
      }
      .autoChangeTransparency(true)
      .set_refresh_sports()
      .ignoredScrollView(contentInsetTop: -58)
      .link(to: collectionView)
      
      header.isCollectionViewAnimationBug = true
      header.endRefreshingAnimationBeginAction = {
          collectionView.collectionViewLayout.finalizeLayoutTransition()
      }

而我的自定义的layout,是重写 layoutAttributesForSupplementaryView(ofKind:at:) 实现头部固定的,请问如何处理这种动画效果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants