Created
November 3, 2018 04:45
-
-
Save TerryCK/a9707bd80a79b4d52de7f237aaca5a12 to your computer and use it in GitHub Desktop.
cover flow for horizontal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func updateCellAttributes(by attributes: UICollectionViewLayoutAttributes) { | |
var minX = collectionView!.bounds.minX + collectionView!.contentInset.left | |
let maxX = attributes.frame.origin.x | |
if minX > attributes.frame.origin.x + attributes.bounds.width + minimumLineSpacing + collectionView!.contentInset.left { | |
minX = 0 | |
} | |
let finalX = max(minX, maxX) | |
var origin = attributes.frame.origin | |
let deltaX = (finalX - origin.x) / attributes.frame.width | |
let translationScale = CGFloat((attributes.zIndex + 1) * 10) | |
// Card stack effect | |
if let itemTransform = firstItemTransform { | |
let scale = 1 - deltaX * itemTransform | |
var t = CGAffineTransform.identity | |
t = t.scaledBy(x: scale, y: scale) | |
if isPreviousCardVisible { | |
t = t.translatedBy(x: (deltaX * translationScale), y: 0) | |
} | |
attributes.transform = t | |
attributes.alpha = scale | |
} | |
origin.x = finalX | |
origin.y = collectionView!.frame.height / 2 - attributes.frame.height / 2 - collectionView!.contentInset.top | |
attributes.frame = CGRect(origin: origin, size: attributes.frame.size) | |
attributes.zIndex = attributes.indexPath.row | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment