I created an app with UICollectionView
like this image:
Added two gestures:
The first (up) will erase the cell.
The second (down) will update the cell (take new data of CoreData). The functions work fine, but there's no animation. iOS has a very cool animation dragging the cell up and the cell disappears.
I am a beginner in animations swift, so I'm a little lost when it.
My question is: How can I add an animation that takes up the entire cell?
I read some answers on the site, but all in Object-C (like this).
Can someone help me?
The best way to achieve the animation on the cell of
UICollectionView
is overriding its layoutUICollectionViewLayout
. Its has method which will return the layout attributes of the cell which you want to either appear/insert/delete.For example: I created a class
KDCollectionViewFlowLayout
inheritingUICollectionViewFlowLayout
and override the delete attribute.Now you need to assign object of this flowLayout to the collection view in either viewDidLoad or you can assign it through storyboard.
Now, you are all set for transformation of cell which you defined in to
finalLayoutAttributesForDisappearingItemAtIndexPath
method whenever you perform any delete operation on thecollectionView
.Update
You need delete the items from collection view using batch operation.