调整单个UICollectionViewCell的大小,是否可能?

bev*_*omb 2 xcode ios uicollectionview uicollectionviewlayout swift

我想知道是否可以调整单个UICollectionViewCell的大小?我一直在看layoutAttributesForItemAtIndexPath和layoutAttributesForElementsInRect之类的东西,但它们都要求你手动设置每个项目的框架,这会变得更麻烦,因为我必须在调整单元格大小后再次计算框架.我的计划是能够选择一个单元格并使其展开以适应屏幕的宽度,并将所有其他单元格向下推,而其他单元格保持其列和行.

有没有人实现这个目标?

谢谢

Mat*_*uch 12

var selectedIndexPath: NSIndexPath?

// MARK: - UICollectionViewDelegate

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    selectedIndexPath = indexPath
    collectionView.performBatchUpdates(nil, completion: nil)
}

// MARK: - UICollectionViewDelegateFlowLayout

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    var size = CGSize(width: 100, height: 100)

    if selectedIndexPath == indexPath {
        size.width = CGRectGetWidth(collectionView.frame)
    }
    return size
}
Run Code Online (Sandbox Code Playgroud)

是的,就这么简单.

(虽然这不是回答问题,如果这是一个好主意.你会看到你实施它;)