我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 模拟器上。
如果关闭反弹效果,则不会发生此问题,但我想保持打开状态以获得更流畅的滚动感觉。我在更新之前/之后尝试使布局无效,但没有结果。感谢您的建议。
编辑(02/26/2019)
解决方法:包装插入以performWithoutAnimation
阻止解决标题消失但显然禁用重新加载动画。
UIView.performWithoutAnimation {
collectionView.performBatchUpdates({
self.collectionView.insertSections(IndexSet(integersIn: collectionView.numberOfSections...viewModel.numberOfSections - 1))
}, completion: nil)
}