IOS - UICollectionView. When you insert several elements at once, how can you fade them out one by one, and not simultaneously?

when you have a collection view and you change elements by inserting several, the default layout immediately mimics them. Is it possible to fade them one by one?

I was thinking of a subclass UICollectionViewLayout, but I'm not sure if this will work.

Do I need to add logic so that multiple inserts do not occur at once? (to insert an element, wait a second, insert the second element, ... Perform it manually). There must be a better way. I hope that

Thanks for any help

+4
source share
1 answer

, , (, asyncAfter) . : . , . :.

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)])
        }
    }
}

:

enter image description here

UICollectionViewLayout.

+3

Source: https://habr.com/ru/post/1690237/


All Articles