gpt4 book ai didi

ios6 - layoutAttributesForItemAtIndexPath - 何时调用?

转载 作者:行者123 更新时间:2023-12-02 22:24:14 25 4
gpt4 key购买 nike

我目前正在研究新的 UICollectionView 的一些演示项目。大多数此类演示都覆盖了子类中的 layoutAttributesForItemAtIndexPath。但是在其中一个示例中从未调用过该方法。

从 Apple 文档我知道我必须覆盖 layoutAttributesForItemAtIndexPath

我想不通这个方法是在什么情况下被调用的。

这种方法只是针对特殊情况吗?

最佳答案

也许你可以在 Apple 文档中找到,子类必须覆盖 layoutAttributesForElementsInRect 和 layoutAttributesForItemAtIndexPath读这个:

    layoutAttributesForElementsInRect:

Returns the layout attributes for all of the cells and views in the specified rectangle.
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
Parameters

rect

The rectangle (specified in the collection view’s coordinate system) containing the target views.

Return Value

An array of UICollectionViewLayoutAttributes objects representing the layout information for the cells and views. The default implementation returns nil.
Discussion

Subclasses must override this method and use it to return layout information for all items whose view intersects the specified rectangle. Your implementation should return attributes for all visual elements, including cells, supplementary views, and decoration views.

When creating the layout attributes, always create an attributes object that represents the correct element type (cell, supplementary, or decoration). The collection view differentiates between attributes for each type and uses that information to make decisions about which views to create and how to manage them.
Availability

Available in iOS 6.0 and later.

Declared In
UICollectionViewLayout.h

关于ios6 - layoutAttributesForItemAtIndexPath - 何时调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com