我向collectionViewLayout
添加了一个自定义的CollectionView
。我有6个单元格,我使用默认动画样式传递下一个项目。但是当我传递最后一个单元格时,我想将动画制作为PageAnimation(自定义)。我在collectionViewLayout
中添加viewDidLoad
,但它会影响所有细胞。
let layout = AnimatedCollectionViewLayout()
layout.animator = PageAttributesAnimator()
layout.scrollDirection = .horizontal
collectionView.collectionViewLayout = layout
如何在一个CollectionView
中使用2种不同的布局类型?
提前致谢。
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
for cell: UICollectionViewCell in clcView.visibleCells {
let indexPath: IndexPath? = clcView.indexPath(for: cell)
if let indexPath = indexPath {
print("\(indexPath)")
if indexPath.row >= 2 {
let layout = AnimatedCollectionViewLayout()
layout.animator = PageAttributesAnimator()
layout.scrollDirection = .horizontal
clcView.collectionViewLayout = layout
}
else {
let layout = AnimatedCollectionViewLayout()
layout.animator = RotateInOutAttributesAnimator()
layout.scrollDirection = .horizontal
clcView.collectionViewLayout = layout
}
}
}
}