Search code examples
iosobjective-cipaduicollectionviewuicollectionviewcell

How to bring a UICollectionViewCell to front?


I recently discovered collection views and now my life is much simpler, but I have an issue. I have (obviously) some cells in the view but what's inside can be pinched. I use an animation that expands outside the cells frame and, as you can imagine, when the circle that is inside the cell gets bigger, the other nearby cells cover it. Before I simply used bringSubviewToFront and everything worked fine. But now I'm confused and have no idea how to "bringCellToFront". So how can I do this? Thank you in advice!


Solution

  • The standard UICollectionViewLayoutAttributes object has a zIndex property (documentation). This determines the front-to-back order of your cells.

    Your layout class should use this to determine which cell is front most. You'd need to have some reference to the cell's index path which you can then pass to the layout object so it knows which z index to apply. You'd probably have to invalidate the layout at the point your animation is triggered, so the cell is front most.