I have a horizontal scrolling UICollectionView
to which I want to add multiple cells that will cause a 2 stage animation to occur:
UICollectionView
scrolls existing cells to the left, showing the empty space where the new cell will appear, then...- The new cell to be inserted then scrolls up vertically from off screen into the empty space.
Imagine the Cells as cards appearing from the bottom of the screen when a user triggers an action.
Currently I have a custom UICollectionViewFlowLayout
with an overridden initialLayoutAttributesForAppearingItem
which will animate the scroll up element of the transition, however after the first item this animation occurs offscreen. I cannot figure out how to scroll the UICollectionView
to the left to show the space where the future cell will appear before the slide up animation occurs.
I have dabbled with contentOffset
changes, however this results in some very jerky and glitchy behaviour.
Whats the best way to approach this?
Current `initialLayoutAttributesForAppearingItem' implementation:
override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attr = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)
attr?.alpha = 0.0
attr?.transform = CGAffineTransform(
translationX: 0,
y: self.collectionView!.bounds.height
)
return attr
}