The best way to achieve animation in a UICollectionView cell is to override its UICollectionViewLayout layout. It has a method that will return the cell layout attributes that you want to either display / insert / delete.
For example: I created the KDCollectionViewFlowLayout class KDCollectionViewFlowLayout inherit from UICollectionViewFlowLayout and overriding the delete attribute.
class KDCollectionViewFlowLayout: UICollectionViewFlowLayout { override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { let attribute = super.finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath) attribute?.transform = CGAffineTransformTranslate(attributes.transform, 0, ITEM_SIZE) attribute?.alpha = 0.0 return attribute } }
Now you need to assign the object of this Layout stream to the collection view in viewDidLoad or you can assign it through the storyboard.
let flowLayout = KDCollectionViewFlowLayout() self.collectionView?.setCollectionViewLayout(flowLayout, animated: true)
You are now set to convert the cell that you defined to the finalLayoutAttributesForDisappearingItemAtIndexPath method whenever you perform a delete operation on collectionView .
Update
You need to remove items from the collection using a batch operation.
collectionView.performBatchUpdates({ () -> Void in //Array of the data which you need to deleted from collection view let indexPaths = [NSIndexPath]() //Delete those entery from the data base. //TODO: Delete the information from database //Now Delete those row from collection View collectionView.deleteItemsAtIndexPaths(indexPaths) }, completion:nil)
source share