【发布时间】:2019-07-18 22:18:41
【问题描述】:
我使用UICollectionReusableView 作为UICollectionView 部分的标题。我启用了“粘性标题”:
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
layout?.sectionHeadersPinToVisibleBounds = true
我正在将新部分插入到集合中:
collectionView.performBatchUpdates({
self.collectionView.insertSections(IndexSet(integersIn: collectionView.numberOfSections...viewModel.numberOfSections - 1))
}, completion: nil)
如果在集合被过度滚动(启用反弹)时发生插入,标题将消失一段时间(参见下面的 GIF)。 如何避免这种行为?
我使用的是 iOS 12.1.4,但同样的问题也发生在 iOS 11.x 和 12.x 模拟器上。
如果关闭反弹效果,则不会发生此问题,但我想保持打开状态以获得更流畅的滚动感觉。我在更新之前/之后尝试使布局无效,但没有结果。感谢您的建议。
编辑(2019 年 2 月 26 日)
解决方法:将插入包装到 performWithoutAnimation 块解决标题消失但显然禁用重新加载动画。
UIView.performWithoutAnimation {
collectionView.performBatchUpdates({
self.collectionView.insertSections(IndexSet(integersIn: collectionView.numberOfSections...viewModel.numberOfSections - 1))
}, completion: nil)
}
【问题讨论】:
标签: ios swift uicollectionview uicollectionreusableview uicollectionviewflowlayout