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
})
}
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With