An extension that makes it easy to apply custom animations to UICollectionView cells.
Applies animation to a single cell.
collectionView.animate(
cell: cell,
parameter: animationParameter
)Applies animation to all visible cells simultaneously.
collectionView.animateVisibleCells(
parameter: animationParameter
)Applies animation to visible cells sequentially by row.
collectionView.animateVisibleCellsByRow(
rowInterval: 0.2, // Delay between each row (seconds)
parameter: animationParameter
)// Configure animation parameters
let animationTypes: Set<PoshmarkCollectionCellAnimationType> = [
.opacity(animationOpacity: (starting: 0, finished: 1)),
.slide(animationSliding: (isToIdentity: true, direction: .vertical, amount: 50))
]
let parameter = CollectionViewCellAnimationParameter(
type: animationTypes,
duration: 0.6,
delay: 0,
springWithDamping: 0.8,
initialSpringVelocity: 0.3,
options: .curveEaseOut
)
// Execute animation
collectionView.animateVisibleCellsByRow(
rowInterval: 0.1,
parameter: parameter
).opacity(animationOpacity: (starting: 0, finished: 1))starting: Starting opacity (0.0 ~ 1.0)finished: Ending opacity (0.0 ~ 1.0)
.slide(animationSliding: (isToIdentity: true, direction: .vertical, amount: 50))isToIdentity: If true, animates from offset position to identity; if false, vice versadirection:.horizontalor.verticalamount: Translation distance (points)
type: Set of animation types (multiple types can be combined)duration: Animation duration (seconds)delay: Animation start delay (seconds)springWithDamping: Spring damping ratio (0.0 ~ 1.0)initialSpringVelocity: Initial spring velocityoptions: UIView animation options
