如何更改一个单元格的 UICollectionViewLayoutAttributes [英] How to change UICollectionViewLayoutAttributes of one cell

查看:19
本文介绍了如何更改一个单元格的 UICollectionViewLayoutAttributes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不重新加载或更改布局对象的情况下更改一个 UICollectionViewCell 的 UICollectionViewLayoutAttributes 属性

I would like to change the UICollectionViewLayoutAttributes attribute of one UICollectionViewCell without reloading or changing the layout object

我做到了

UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];

attributes.transform = CGAffineTransformMakeScale(1.5, 1.5);

但这并没有传播到细胞 - 如何做到这一点?

But this isn't propagating to the cell - how can this be done?

推荐答案

-[UICollectionView layoutAttributesFor...] 方法返回布局属性的副本.布局返回原件后,您将无法修改原件.

-[UICollectionView layoutAttributesFor...] methods return copies of the layout attributes. You can't modify the originals after the layout returns them.

最好的办法是对布局进行子类化,并且无论何时返回该项目的属性(在 layoutAttributesForItem 或 layoutAttributesForElementsInRect 中),都返回修改后的属性.

Your best bet is to subclass the layout, and whenever you return the attributes for that item (either in layoutAttributesForItem or layoutAttributesForElementsInRect), return the modified attributes.

如果更改确实是暂时的,您可以随时手动操作单元格变换.集合视图并不真正关心——不过,它可能会在需要重新加载单元格时重新应用属性.

If the change is really really temporary, you can always manipulate the cell transform manually. The collection view doesn't really care -- it may reapply the attributes when the cell needs to be reloaded, though.

这篇关于如何更改一个单元格的 UICollectionViewLayoutAttributes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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