1

I'm looking to expand the height of the top cell in my collectionview with animation. The problem is when I detect a tap on the cell, I try animating the height and set the new height in the delegate: - collectionView:layout:sizeForItemAtIndexPath:indexPath. The issue I see an instant refresh after invalidating my collection flow layout and the animation happens afterwords. The effect I want is for the top cell to animate the expansion to the new height and push the rows beneath it along with the animation.

I'm only using one section with multiple rows. Should I try to use two sections and put the top cell in the first section and the remaining in the second section? Could I then animate the second section along with the height of the first section?

samonderous
  • 649
  • 1
  • 10
  • 22
  • Check this http://stackoverflow.com/questions/13780153/uicollectionview-animate-cell-size-change-on-selection – manya Mar 01 '14 at 05:36
  • This doesn't seem to work as expected. The cell does animate but has the hight increases the cell hides behind the next cell's view. It does not push the next cell down, increasing the overall contentSize. – samonderous Mar 04 '14 at 00:39

1 Answers1

-1

You need to do this three steps:

1.Invalidate your collectionViewLayout

self.collectionView.collectionViewLayout.invalidateLayout()

2.Reload desired indexPath or all the data inside a performBatchUpdates block

collectionView.performBatchUpdates({
            self.collectionView.reload(at: DESIRED_INDEXPATH)
        }, completion: nil)

3.Return the new height calculated in sizeForItemAtIndexpath delegate method

MarMass
  • 5,755
  • 1
  • 18
  • 15