'Wrong animation when insert or delete items in UICollectionView
I want insert item in the collectionView, if collectionView offset equal 0 no problems observed, But if I scroll my collection and after that try insert new item, my collection starts acting weird.
All items are compressed, then decompressed at the beginning of the collection
(All inserting into 0 index)
DeleteItem
calls the same effect
I assume that the collection includes an animation to insert a item, and at the same time it scrolls to this new item, two animations overlap each other. (That's what I found out, read other answers)
Why the animation breaks when removed - I, unfortunately, do not know, I hope you help me)
My code for insert and delete items:
insert:
// Calls in collectionView custom class
func insertTag(_ tag: String) {
tags.insert(tag, at: 0)
performBatchUpdates {
self.insertItems(at: [.init(item: 0, section: 0)])
}
}
delete:
// Calls on collectionView custom class
func removeTag(_ tag: String) {
let deletedIndex = tags.firstIndex(of: tag)
guard let deletedIndex = deletedIndex else { return }
tags.remove(at: deletedIndex)
deleteItems(at: [.init(item: deletedIndex, section: 0)])
}
Insert item (when contentOffset > 0)
Delete item (when contentOffset > 0)
I really hope that you will help me figure it out, I'm sure that the solution should be on the surface (I think so)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|