I am trying to mimic Instagram live comments section where the first cell in the UICollectionView
appears at the bottom but the flow is still top to bottom. I.e. everything about the flow layout is the exact same except that the first cell is at position (x: 0, y: heightOfCollectionView)
...
Below is my naive implementation. I also thought about having the collection view increment in height per item in the UICollectionView
until themaxY >= centerY
of the superview
.
import UIKit
class CommentsLayout: UICollectionViewFlowLayout {
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let layoutAttribute = super.layoutAttributesForItem(at: indexPath)?.copy() as! UICollectionViewLayoutAttributes
if indexPath.section == 1 {
print(collectionView?.frame.size.height)
layoutAttribute.frame = CGRect(x: 0, y: 600, width: collectionViewContentSize.width, height: 40)
}
return layoutAttribute
}
}