Reputation: 6567
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
})
}
Upvotes: 6
Views: 1308
Reputation: 1319
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)
}
Upvotes: 2