UICollectionView列网格间隙

Swa*_*nil 7 objective-c ios uicollectionview

UICollectionView在我的iPad应用程序中使用流布局.我有不同宽度和高度的细胞.当我使用UICollectionViewFlowLayout作为集合视图的布局的子类时,它显示了单元格之间的间隙.

如果列中有大单元格,则会使该列的网格和小单元格呈现为列中的大单元格的居中.有没有更好的方法来紧密细胞包裹?

我正在使用水平滚动.我尝试使用layoutAttributesForElementsInRect:方法,但没有成功.

如果有人通过使用layoutAttributesForElementsInRect:方法或其他方式做同样的事情,请告诉我...

请找附件.我需要同样的解决方案在此输入图像描述

提前致谢...

小智 0

我对 UICollectionViewFlowLayout 进行了子类化,并在我的layoutAttributesForItemAtIndexPath: 和layoutAttributesForElementsInRect: 方法中我有一个称为

setLineAttributes:(UICollectionViewLayoutAttributes *)attributes visibleRect:(CGRect)visibleRect:
Run Code Online (Sandbox Code Playgroud)

其中包含:

if (attributes.indexPath.item == 0 || attributes.indexPath.item == 1 || attributes.indexPath.item == 2) {
    CGRect f = attributes.frame;
    f.origin.x = 0;
    attributes.frame = f;
} else {
    NSIndexPath *ipPrev = [NSIndexPath indexPathForItem:attributes.indexPath.item - 3 inSection:attributes.indexPath.section];
    CGRect fPrev = [self layoutAttributesForItemAtIndexPath:ipPrev].frame;
    CGFloat rightPrev = fPrev.origin.x + fPrev.size.width + 10;
    if (attributes.frame.origin.x <= rightPrev) 
        return;

    CGRect f = attributes.frame;
    f.origin.x = rightPrev;
    attributes.frame = f;
}
Run Code Online (Sandbox Code Playgroud)