Fattie
Fattie

Reputation: 12272

Animating performBatchUpdates in UICollectionView - how to remove the fade style?

I have a typical ...

"user selects one row, all other rows go away, there is now only one row in the data source, the row's new position is (obviously) now the top and only row: row X slides up to that new position"

... animation, which you do with ...

    data .. update to the final data (now only ONE section)
    coll.performBatchUpdates({
        coll.deleteSections(removeIndexPathSections)
        coll.moveSection(indexPathOfTargetRow, toSection: 0)
        
    }) { _ in
        completion()
    }

Example: the rows (ie, sections) of the collection

A
B
C
D
E

(TBC typically there would be 100s of rows.) The user clicks "D" row and we get

D

ie: removeIndexPathSections would be [0,1,2,4]

and indexPathOfTargetRow would be 3

This works fine but if you try this in collection view what happens in detail is

  1. the four rows fade away over the half second

  2. the "D" row slides up to the top position over the same half-second

That's fine. But I would prefer

  1. the four rows instantly disappear

  2. the "D" row slides up to the top position over a half-second

I can't find a way to do this. Is it possible?


My workaround is just to run this sort of code first ..

    let viz = coll.indexPathsForVisibleItems
    for v in viz {
        if v.section == 0 { continue }
        if v.section == indexPathOfTargetRow { continue }
        coll.cellForItem(at: v)?.isHidden = true
        // don't forget due to this you have to unhide
        // in prepareForReuse every cell type used :/
    }
    .. then the above code ..

.. which is a shame.

In related approaches,

  1. perhaps there's a way to run the two animations sequentially versus simultaneously?

  2. perhaps you can set the animation time, or, each of the two animations differently?

  3. You can changed the peed with coll.forFirstBaselineLayout.layer.speed = .. but I could not find how to independently change the two animations.

Any ideas ?

Upvotes: 0

Views: 45

Answers (0)

Related Questions