ios6 - layoutAttributesForItemAtIndexPath - 何时调用?

标签 ios6 uicollectionview

我目前正在研究新 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/

相关文章:

ios - 数组中的图像未显示在 UICollectionview 中

swift - 如何获取 UICollectionView 中每个选定单元格的按钮标题?

ios - 将 UIImage 分配给 Collection View 单元格

javascript - HTML5视频自动播放,不带自动播放属性

iphone - 在横向和水平 iPhone 位置下使用 ZBarReader 拍照时出现问题

iphone - 所有 View 中的 Ios 音频播放器

ios - 如何在指定时间后淡出 UICollectionViewCell

ios - 在 iOS6 中使用 Storyboard ,我如何以模式切换到另一个 View ,但该 View 有一个导航栏

使用 PhoneGap 2.1.0 和 iOS 6 锁定 iPhone 时无法播放 HTML 5 音频 MP3 文件

ios - 为什么我的 UICollectionView 在单击单元格时会向上滚动?