Swift在同一个UICollectionView中有多个行为

问题描述 投票:5回答:1

我向collectionViewLayout添加了一个自定义的CollectionView。我有6个单元格,我使用默认动画样式传递下一个项目。但是当我传递最后一个单元格时,我想将动画制作为PageAnimation(自定义)。我在collectionViewLayout中添加viewDidLoad,但它会影响所有细胞。

let layout = AnimatedCollectionViewLayout()
layout.animator = PageAttributesAnimator()
layout.scrollDirection = .horizontal
collectionView.collectionViewLayout = layout

如何在一个CollectionView中使用2种不同的布局类型?

提前致谢。

ios swift uicollectionview uicollectionviewlayout
1个回答
0
投票
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
                }
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.