【问题标题】:UICollectionView custom layoutsUICollectionView 自定义布局
【发布时间】:2013-02-02 23:19:40
【问题描述】:

您好,我正在开始 iOS 开发,并且正在玩 UICollectionView。我只是想知道如何实现这种类型的布局。如下所示: 这个想法是在大牢房里有一篇主要的新闻文章。只是混淆了我如何在第二列中获得两个单元格。非常感谢!

【问题讨论】:

    标签: layout ios6 uicollectionview


    【解决方案1】:

    创建自定义类,作为集合视图的布局。这个类将是 UICollectionViewFlowLayout 的子类。

    然后您可以覆盖以下两种方法,并可以根据需要创建自己的自定义布局。

      - (NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
      - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path
    

    UICollectionViewLayoutAttributes 是处理单元格位置、框架、Zindex 等的类

    您还可以使用以下属性。

     collectionView:layout:minimumInteritemSpacingForSectionAtIndex:
     collectionView:layout:minimumLineSpacingForSectionAtIndex:
    

    【讨论】:

    • 我也实现了类似的布局,但在cellForRowAtIndexPath 中认为旧的可见矩形是在layoutAttributesForElementsInRect: 之前调用委托方法,这导致我的应用程序中可见单元格闪烁(重新加载)。你是如何避免这个问题的。
    猜你喜欢
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 2012-10-11
    • 2015-07-07
    • 1970-01-01
    相关资源
    最近更新 更多