自定义UICollectionViewFlowLayout动画

ban*_*isa 13 ios uicollectionviewlayout

我有一个自定义的UICollectionViewFlowLayout动画,它通过插入从右侧错开视图,并在左侧错开视图.它通过在UICollectionViewLayoutAttributes上设置CABasicAnimation并将其应用于单元层来实现.

屏幕抓取

GitHub上的CollectionViewAnimations项目

默认的alpha为0,它淡出我的单元格并提前结束我的自定义动画.如果我将alpha更改为1,那么我根本看不到我的动画.我把它设置为0.5,我得到了两个......这很奇怪.你必须运行我的项目才能看到我的意思.

AnimatingFlowLayout.swift

出于某种原因,我似乎无法完全删除finalLayoutAttributesForDisappearingItemAtIndexPath中属性的默认alpha.

有人有任何想法吗?

lib*_*bec 1

您正在使用performBatchUpdates(_:completion:)的已经对您在 中设置的更改进行了动画处理 finalLayoutAttributesForDisappearingItemAtIndexPath(_:),因此,如果您添加 ,CABasicAnimation则将动画添加到已经发生的动画中。如果你从你的动画中删除CellLayoutAttributes并只设置transform3DUICollectionViewLayoutAttributes会做你想做的事(除了动画beginTimefillMode)。这段代码对我来说效果很好:

override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
    let attributes: CellLayoutAttributes = super.finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath) as! CellLayoutAttributes
    // Default is 0, if I set it to 1.0 you don't see anything happen..'
    attributes.alpha = 1
    let endX = -CGRectGetWidth(self.collectionView!.frame)
    var endTransform: CATransform3D = CATransform3DMakeTranslation(endX, 0, 0)
    attributes.transform3D = endTransform

    return attributes
} 
Run Code Online (Sandbox Code Playgroud)