UICollectionView:不对重复使用的项目计算不同大小的项目 [英] UICollectionView: different size items is not calculated on reused items

查看:270
本文介绍了UICollectionView:不对重复使用的项目计算不同大小的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集合视图,其中包含我在

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:不对重复使用的项目计算不同大小的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆