layoutAttributesForItemAtIndexPath - 何时调用?

Tho*_*len 2 ios6 uicollectionview

我目前正在为新的UICollectionView玩一些演示项目.这些演示中的大多数都layoutAttributesForItemAtIndexPath在子类中重写.但是在该示例之一中从不调用该方法.

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

我不禁想出这种方法被调用的情况.

这种方法仅适用于特殊情况吗?

kim*_*aro 5

也许你可以在Apple doc中找到,Subclasses必须覆盖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
Run Code Online (Sandbox Code Playgroud)