UICollectionView layout last row

I am currently working on a UICollectionView . I have been looking all over SO and found several issues to this problem, but none of those had an answer to the problem. Maybe if i collect all the facts in one question here, one can provide a solution to this issue:

If I have a collectionView with a simple UICollectionViewFlowLayout subclass, all works fine but the last row. I do everything with autoLayout . The cells align just fine, they fill out the row as soon as a new row starts. The only problem there is that the last row's layout is still as it would wait for another item to be added.

Now, some code, here's my UICollectionViewFlow subclass:

@implementation SubCollectionViewFlowLayout
- (instancetype)init {
    self = [super init];
    if (self) {
        self.estimatedItemSize = CGSizeMake(100, 100);
        self.minimumInteritemSpacing = 5.0f;
        self.minimumLineSpacing = 5.0f;
        self.scrollDirection = UICollectionViewScrollDirectionVertical;
    }
    return self;
}

This is the whole subclassing. So it really is just basic.

So when looking for another issue with this problem, i found the following SO Questions. The first one is exactly my probelm, the others seem to be similar.

  • UICollectionView layout of last cell

  • UICollectionView estimatedItemSize - last cell is not aligned

  • UICollectionView last cell not aligned

  • Last item in UICollectionView not alligned - Swift

  • I hope this is enough description for the problem, help is as always much appreciated.


    After some research, I guess it is not possible to solve this smoothly.

    However there is a possibility to solve it, described in this Answer.

    One just adds an additional cell with height=0 and width=collectionViewWidth. Tested this and works perfectly fine.

    链接地址: http://www.djcxy.com/p/84168.html

    上一篇: javax vs java包

    下一篇: UICollectionView布局最后一行