gpt4 book ai didi

ios - Animate UICollectionViewLayout header 大小会导致不必要的 Flash 交叉溶解

转载 作者:行者123 更新时间:2023-11-30 12:30:29 25 4
gpt4 key购买 nike

问题的可见性:http://i.imgur.com/TastPR9.gifv

func animateHeaderResize(height: CGFloat) {

let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout;
layout.headerReferenceSize = CGSize(width: UIScreen.main.bounds.width, height: height);

UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut, animations: {
self.collectionView?.layoutIfNeeded();
}) { (finished) in
//self.loadPosts();
}
}

我正在尝试通过 UICollectionViewLayout 来动画显示 UICollectionView header 大小的变化。生成的动画有奇怪的闪光和拉伸(stretch),这可能是在某处触发的交叉溶解过渡。我尝试了设置 Collection View 布局的多种变体,包括 setCollectionViewLayout(layout:animated:) 和实现 collectionView(_ collectionView:layout:referenceSizeForHeaderInSectionsection:) 但所有结果都是相同的动画。

我注意到,更改 Collection View 的项目大小时会发生相同的闪烁。也许这是我可以修改的一些默认行为?我必须继承 UICollectionViewFlowLayout 的子类吗?我尝试过搜索,但找不到解决方案,希望朝正确的方向迈出一步。

最佳答案

这最终对我有用:

func animateHeaderResize(height: CGFloat) {

self.collectionView?.performBatchUpdates({
let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout;
layout.headerReferenceSize = CGSize(width: UIScreen.main.bounds.width, height: height);
}, completion: { (fin) in
self.loadPosts();
});

}

关于ios - Animate UICollectionViewLayout header 大小会导致不必要的 Flash 交叉溶解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43621051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com