gpt4 book ai didi

ios - UICollectionViewCell 在 sizeForItemAt 中不可用

转载 作者:行者123 更新时间:2023-11-29 11:51:32 25 4
gpt4 key购买 nike

我正在尝试在 Collection View 中设置单元格大小变化的动画。

在“didSelectItemAt”中:

            collectionView.performBatchUpdates({
collectionView.collectionViewLayout.invalidateLayout()
let cell = collectionView.cellForItem(at: indexPath)
let frame = cell?.frame
cell?.frame = CGRect(x: (frame?.origin.x)!, y: (frame?.origin.y)!, width: (frame?.size.width)! + 100, height: (frame?.size.height)!)
}, completion: nil)

应该设置单元格的大小,但没有任何反应。再次单击该单元格,我看到该单元格的大小保留为 size+100(忽略它每次都会增长的事实 - 只是试图让它立即工作)。

在 sizeForItemAt 函数中,任何检索单元格的尝试都会返回 nil。

collectionView.numberOfItems(inSection: indexPath.section)

返回 3,但是

collectionView.cellForItem(at: indexPath)

返回零。为什么?

如何在 sizeForItemAt 范围内获取具有给定索引路径的 Collection View 的单元格:???

最佳答案

显然 sizeForItemAt 在 cellForItem 之前被调用。

关于ios - UICollectionViewCell 在 sizeForItemAt 中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com