Skip to content

Instantly share code, notes, and snippets.

@psaitu
Last active January 25, 2016 05:51
Show Gist options
  • Select an option

  • Save psaitu/28b7caa0da4cb0d17ec4 to your computer and use it in GitHub Desktop.

Select an option

Save psaitu/28b7caa0da4cb0d17ec4 to your computer and use it in GitHub Desktop.
Corner Flow Layout In Swift
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