我有一个集合视图,其中包含我在
I have a collection view with varied item sizes which i declare in
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { FeedItem *item = [_imagesLinkArray objectAtIndex:indexPath.row]; return CGSizeMake(250, 200*item.sizeFactor); }在collectionView:cellForItemAtIndexPath:中重用单元格时 该项目将使用所需的项目大小而不是sizeForItemAtIndexPath:中指定的大小进行渲染.
When the cell is being reused in collectionView:cellForItemAtIndexPath: the item is being rendered with the reuesed item size and not the one specified in sizeForItemAtIndexPath:.
有什么想法吗?
推荐答案似乎collectionView:layout:sizeForItemAtIndexPath:在布局准备中调用一次,即呈现CollectionView之前.
It seems that collectionView:layout:sizeForItemAtIndexPath: is called once on layout preparation, before CollectionView is rendered.
因此,每当滚动并退出单元格时,它就会在准备阶段调整为collectionView:layout:sizeForItemAtIndexPath:提供的大小.您是否希望每当具有特定indexPath的单元格可见时都将调用此方法?这样您就可以动态更改单元格大小?似乎这不是可以使用的方法,它可以在布局准备阶段一次确定单元的大小.
So whenever you scroll and a cell is dequeued it is resized to the size provided by collectionView:layout:sizeForItemAtIndexPath: at preparation stage. Are you expecting this method to be called whenever a cell with certain indexPath gets visible? So that you can dynamically change cell size? seems this is not how this method can be used, it can be used to determine the size of a cell once at layout preparation stage.
如果由于某种原因需要重新计算尺寸,可以使用[UICollectionViewLayout invalidateLayout]使布局无效.
In case you need the sizes to be recomputed for some reason, you can invalidate the layout using [UICollectionViewLayout invalidateLayout].
更多推荐
UICollectionView:不对重复使用的项目计算不同大小的项目
发布评论