Last active
November 13, 2015 21:12
-
-
Save inlinestyle/30018d5629cd84fc3b4a to your computer and use it in GitHub Desktop.
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
class GCFixedColumnHorizontalScrollingCollectionViewFlowLayout: UICollectionViewFlowLayout { | |
var numberOfRows: UInt = 0 | |
var numberOfFixedColumns: UInt = 0 | |
var columnWidth: UInt = 0 | |
init(numberOfFixedColumns: UInt, columnWidth: UInt) { | |
self.numberOfFixedColumns = numberOfFixedColumns | |
self.columnWidth = columnWidth | |
super.init() | |
self.scrollDirection = .Horizontal | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { | |
return true | |
} | |
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
let fixedIndexes = numberOfRows * numberOfFixedColumns | |
var attributesArray = super.layoutAttributesForElementsInRect(rect)?.filter({ (let attributes) -> Bool in | |
return attributes.indexPath.row >= Int(fixedIndexes) | |
}) | |
for index in 0..<fixedIndexes { | |
if let attributes = self.layoutAttributesForItemAtIndexPath(NSIndexPath(forRow: Int(index), inSection: 0)) { | |
let frame = attributes.frame | |
let column = index / numberOfRows | |
attributes.zIndex = 1 | |
attributes.frame = CGRect(x: self.collectionView!.contentOffset.x + CGFloat(columnWidth * column), y: frame.origin.y, width: frame.width, height: frame.height) | |
attributesArray?.append(attributes) | |
} | |
} | |
return attributesArray | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment