Last active
January 25, 2016 05:51
-
-
Save psaitu/28b7caa0da4cb0d17ec4 to your computer and use it in GitHub Desktop.
Corner Flow Layout In Swift
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
| import UIKit | |
| class CornerFlowLayout: UICollectionViewFlowLayout { | |
| var itemTransform:CGFloat! | |
| override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
| let oldItems = super.layoutAttributesForElementsInRect(rect)! | |
| let allItems = oldItems | |
| for (_, object) in allItems.enumerate() { | |
| let attributes:UICollectionViewLayoutAttributes = object | |
| self.updateCellAttributes(attributes) | |
| } | |
| return allItems | |
| } | |
| func updateCellAttributes(attributes: UICollectionViewLayoutAttributes) { | |
| let minY = CGRectGetMinY((self.collectionView?.bounds)!) + (self.collectionView?.contentInset.top)! | |
| let maxY = attributes.frame.origin.y | |
| let finalY = max(minY, maxY) | |
| var origin:CGPoint = attributes.frame.origin | |
| origin.y = finalY | |
| attributes.frame = CGRect(origin: origin, size: attributes.frame.size) | |
| attributes.zIndex = attributes.indexPath.row | |
| } | |
| override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { | |
| return true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment