7

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

如果列中有大单元格,它会使该列的网格和小单元格呈现在列中该大单元格的中心。有没有更好的方法来紧紧包裹细胞?

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

layoutAttributesForElementsInRect:请让我知道是否有人通过使用方法或其他方式做过同样的事情......

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

提前致谢...

4

2 回答 2

1

像这样使用

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];

layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 2;
于 2013-12-21T13:09:18.783 回答
0

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

setLineAttributes:(UICollectionViewLayoutAttributes *)attributes visibleRect:(CGRect)visibleRect:

其中包含:

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;
}
于 2013-01-12T00:57:12.253 回答