我正在尝试在集合视图中为单元格大小更改设置动画。UICollectionViewCell在sizeForItemAt中不可用
在 '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)
这应该设置单元格的大小,但没有任何反应。再次单击单元格时,我发现单元格的大小保持为+ 100(忽略每次都会增长的事实 - 只是试图立即使用它)。
在sizeForItemAt函数中,任何尝试检索单元格都返回nil。
collectionView.numberOfItems(inSection: indexPath.section)
回报3,但
collectionView.cellForItem(at: indexPath)
返回nil。为什么?
我怎样才能得到该单元格的大小为ItemForItemAt范围内给定的索引路径: ???
是的,它肯定是0.我遇到的问题是,在第一个.reloadData()已经运行并且所有代表被调用之前,我正在查看该代码的执行情况。换句话说,该表尚未填充数据。 –