菜鸟教程小白 发表于 2022-12-12 16:16:36

ios - 如何更改一个单元格的 UICollectionViewLayoutAttributes


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

<p>我做到了</p>

<pre><code>UICollectionViewLayoutAttributes *attributes = ;

attributes.transform = CGAffineTransformMakeScale(1.5, 1.5);
</code></pre>

<p>但这不会传播到单元格 - 这怎么能做到?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><code>-</code> 方法返回布局属性的副本。布局返回后,您无法修改原件。</p>

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

<p>如果更改确实是暂时的,您始终可以手动操作单元格变换。 Collection View 并不真正关心——不过,它可能会在需要重新加载单元格时重新应用属性。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何更改一个单元格的 UICollectionViewLayoutAttributes,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/19901423/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/19901423/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何更改一个单元格的 UICollectionViewLayoutAttributes