最后一个单元格的UICollectionView布局

时间:2014-07-21 08:33:11

标签: uicollectionview flowlayout

我有一个具有UICollectionViewFlowLayout的collectionview 我放了10件物品。它们有不同的尺寸:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

if (indexPath.row<6) {
    CGSize retval =  CGSizeMake(100, 100);
    return retval;
}

CGSize retval =  CGSizeMake(200, 130);

return retval;
}

它的布局如下: 前6个单元看起来很好,7-9是正确的,但最后一个不是中心对齐,

enter image description here enter image description here

任何人都可以向我解释这个问题吗?

和怨恨的日子我正在玩收集布局,但仍然对选择感到困惑 流程图和自定义布局。关于这个的任何原则?

提前许多事。

1 个答案:

答案 0 :(得分:4)

我遇到了类似的问题,集合视图中的最后几个单元格具有难看的偏移量。在我的情况下,这是因为没有尊重关于物品尺寸的部分插入物。

尝试将flowLayout的sectionInset设置为0:

flowLayout.sectionInset = UIEdgeInsetsZero;

如果这不起作用,您可能需要强制执行minimumInterItemSpacing,因为流布局似乎会在最后几个单元格中出现错误:

flowLayout.minimumInteritemSpacing = 10.f;//or any reasonable number