I've got a custom UICollectionViewFlowLayout animation that staggers views in from the right with insertions and out to the left with deletions. It does it by setting a CABasicAnimation on the UICollectionViewLayoutAttributes and applying this to the cell layer.
CollectionViewAnimations Project on GitHub
The default alpha is 0 and its fading out my cells and ending my custom animation early. If I change the alpha to 1 then i don't see my animation at all. I set it at 0.5 and I get a bit of both.... it's weird. You'd have to run my project to see what I mean.
AnimatingFlowLayout.swift
For some reason, I can't seem to completely remove the default alpha on the attributes in finalLayoutAttributesForDisappearingItemAtIndexPath.
Anyone got any ideas?
You're using performBatchUpdates(_:completion:)
which already animates the changes you set in finalLayoutAttributesForDisappearingItemAtIndexPath(_:)
, so if you add the CABasicAnimation
you're adding animation to animation that's already gonna happen. If you drop the animation from your CellLayoutAttributes
and just set the transform3D
of UICollectionViewLayoutAttributes
it's gonna do what you want (except the animation beginTime
and fillMode
). This piece of code works well for me:
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
}
This worked for me, for a similar problem:
import UIKit
class NoFadeFlowLayout: UICollectionViewFlowLayout {
override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)
attrs?.alpha = 1.0
return attrs
}
override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath)
attrs?.alpha = 1.0
return attrs
}
}
You said you couldn't get the default alpha to go away in this method, but it worked when I tried it on tvOS 11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With