Skip to content

Instantly share code, notes, and snippets.

@KelvinJin
Created February 9, 2017 06:11
Show Gist options
  • Save KelvinJin/16aa06923b15fab9a23cb4135fe80433 to your computer and use it in GitHub Desktop.
Save KelvinJin/16aa06923b15fab9a23cb4135fe80433 to your computer and use it in GitHub Desktop.
import UIKit
class ParallaxCollectionViewLayout: UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return super.layoutAttributesForElements(in: rect)?.flatMap { $0.copy() as? UICollectionViewLayoutAttributes }.flatMap(addParallaxToAttributes)
}
private func addParallaxToAttributes(_ attributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
return attributes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment