1

我正在尝试模仿 Instagram 实时评论部分,其中第一个单元格UICollectionView出现在底部,但流程仍然是从上到下的。即关于流布局的一切都是完全相同的,除了第一个单元格在位置(x: 0, y: heightOfCollectionView)......

下面是我的幼稚实现。我还考虑过让集合视图UICollectionViewmaxY >= centerY.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
}

}

4

0 回答 0