I’m thinking about subclassing UICollectionViewLayout, but I’m not sure if this will work like that.
Do I really have to add logic so that it doesn’t happen multiple times at the same time Inserts? (This way I insert a project, wait a minute, insert the second project,…manually complete) There must be a better way. I hope
Thank you for your help
p>
private func append(_ objectsToAdd: [Foo]) {
for i in 0 ..< objectsToAdd.count {
DispatchQueue.main.asyncAfter(deadline : .now() + Double(i) * 0.25) {
self.objects.append(objectsToAdd[i])
self.collectionView?.insertItems(at: [IndexPath(item: self.objects .count-1, section: 0)])
}
}
}
Yield:
No need to subclass UICollectionViewLayout.
If you have a collection view and you change items by inserting several, the default layout will fade them out at the same time. Is it possible to fade them one by one?
I’m thinking about subclassing UICollectionViewLayout, but I’m not sure if this will work like that.
Do I really have to add logic so that it doesn’t happen multiple times at the same time Inserts? (In this way I insert a project, wait a minute, insert the second project,…manually complete) There must be a better way. I hope
Thank you for your help
If you want to fade them out at once, you will have to add one to the model and reload that item and then delay (e.g. asyncAfter) and execute the next item. Please note that you cannot add all of them at once In the model, you only need to delay reloading the items of the collection view. You must postpone the update of the model and reload the corresponding items of the collection view. For example.:
private func append(_ objectsToAdd: [Foo]) {
for i in 0 ..< objectsToAdd.count {
DispatchQueue.main.asyncAfter(deadline: .now() + Double(i) * 0.25 ) {
self.objects.append(objectsToAdd[i])
self.collectionView?.insertItems(at: [IndexPath(item: self.objects.count-1, section: 0)])< br /> }
}
}
Output:
No need to subclass UICollectionViewLayout.