I need to obtain Fold animation when the person scrolls UICollectionView
. I’ve UICollectionView
with full-screen dimension cell and vertically scrolling with paging enabled. For that I’ve created sub-class of UICollectionViewFlowLayout
which is as described under.
class FoldingFlowLayout: UICollectionViewFlowLayout {
override func put together() {
tremendous.put together()
scrollDirection = .vertical
minimumLineSpacing = 0
minimumInteritemSpacing = 0
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes = tremendous.layoutAttributesForElements(in: rect)
attributes?.forEach { attribute in
transformLayoutAttributes(attribute)
}
return attributes
}
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return true
}
non-public func transformLayoutAttributes(_ attributes: UICollectionViewLayoutAttributes) {
guard let collectionView = collectionView else { return }
let contentOffsetY = collectionView.contentOffset.y
let cellOffsetY = attributes.body.origin.y - contentOffsetY
let cellHeight = attributes.body.peak
var rework = CATransform3DIdentity
rework.m34 = -1.0 / 500.0 // Apply perspective
if cellOffsetY < cellHeight && cellOffsetY > -cellHeight {
let angle = (cellOffsetY / cellHeight) * .pi / 2
rework = CATransform3DRotate(rework, angle, -1, 0, 0)
attributes.transform3D = rework
attributes.alpha = 1.0 - (abs(cellOffsetY) / cellHeight)
} else {
attributes.transform3D = CATransform3DIdentity
attributes.alpha = 1.0
}
}
}
However this isn’t working as I anticipated. I need to create duplicate of this sort of animation.
What am I lacking right here?