UICollectionView:不对重复使用的项目计算不同大小的项目

编程入门 行业动态 更新时间:2024-10-22 13:39:41
本文介绍了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:不对重复使用的项目计算不同大小的项目

本文发布于:2023-11-08 13:47:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569543.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   重复使用   大小   UICollectionView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!