T
T
timoninas12022-04-08 12:45:50
iOS
timoninas1, 2022-04-08 12:45:50

Why doesn't UICollectionView zIndex work in UICollectionViewLayoutAttributes?

I'm trying to make the very first cell in the collectionView be behind all the others. Even when the next cell overlaps (floats) a little on the first cell

┌──────────┐ 
│          │ 
│  Cell 0  │ 
│┌─────────┴┐
└┤          │
 │  Cell 4  │
 │          │
 └──────────┘
 ┌──────────┐
 │          │
 │  Cell 5  │
 │          │
 └──────────┘
 ┌──────────┐
 │          │
 │  Cell 6  │
 │          │
 └──────────┘


Tried to add behavior in custom layout via zIndex as follows

Code in custom layout
override func prepare() {
  super.prepare()
  /// Some code
  
  let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
  attributes.zIndex = zIndex
  
  /// Some code
}


Code in cell (cell) collection

override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
    super.apply(layoutAttributes)
    layer.zPosition = CGFloat(layoutAttributes.zIndex)
}


But the desired behavior is not obtained. When reused, the cell first rises to the front position

Tell me who faced such a problem, what I'm doing wrong

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question