6

I would like to animate the resizing of a UICollectionViewCell. I have written the code below but cannot have the return line inside the animation block. Any ideas?

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

    var newSize = CGSize(width: (self.view.frame.width), height: 0)


    UIView.animateWithDuration(2.0, animations: { () -> Void in
        return newSize
    })

}
Tom Coomer
  • 6,227
  • 12
  • 45
  • 82

1 Answers1

2

Call following method if you want to animate,

self.collectionView.performBatchUpdates(updates: (() -> Void), completion:((Bool) -> Void)?)

More specifically, you should also handle orientation change, like below,

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation)
{
    self.collectionView.performBatchUpdates(nil, completion: nil)

}
iEngineer
  • 1,319
  • 1
  • 11
  • 27