Question: I'd really appreciate if someone can light up some ideas here. I've been trying to fix this for weeks now (not kidding).

I have a "to do list" using a collectionView where I hide the rows that were completed and move them to the end of the list. I then unhide the items if needed with a button. The collectionView looks exactly as a tableView with one item(cell) per row.

When the items are hidden the collectionView has a lot of empty scrolling space at the bottom instead of automatically deleting the space used by the hidden rows since they technically are still there.

I'm trying to cut that empty space so the collectionView height would be equal to the amount of cells/rows left visible.

```
override func viewDidAppear(animated: Bool) {

if isCellHidden { //checking if cells are hidden 
var heightOfSection0 = 95 + (42 * self.collectionView.numberOfItemsInSection(0))
println(self.collectionView.contentSize.heigh) //returns 2350
self.collectionView.contentSize.height = CGFloat(heightOfSection0)
println(heightOfSection0) //returns 1019
println(self.collectionView.contentSize.heigh) //returns 1019.0 which is correct but as soon as I scroll down it resets to it's original size (2350) and let's me scroll through that empty space...
}}

```

If I try to read the collectionView height immediately after setting this, it displays the correct value but as soon as I try to scroll down it resets back to it's original height. I also tried disabling the auto layout and it doesn't make a difference

Answer: 
You can use `sizeForItemAtIndexPath:` to change the size of collection view cell.

```
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    var numberOfCellInRow : Int = 3
    var padding : Int = 5
    var collectionCellWidth : CGFloat = (self.view.frame.size.width/CGFloat(numberOfCellInRow)) - CGFloat(padding)
    return CGSize(width: collectionCellWidth , height: collectionCellWidth)
}

```
Changing UI stuff in `viewDidAppear()` in theory is a good place to do so. However, at this point, you can't be sure that auto layout has operated on the subview that you're manipulating.

You can check when it has and when it's safe to manipulate the frame, by subclassing it and overriding `layoutSubviews()`

I had a similar issue here: <https://stackoverflow.com/a/30446125/4396258>