6

UICollectionView setLayout: animated: does not preserve z Index

 3 years ago
source link: https://www.codesd.com/item/uicollectionview-setlayout-animated-does-not-preserve-z-index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

UICollectionView setLayout: animated: does not preserve z Index

advertisements

I've noticed that when calling setLayout:animated in a UICollectionView to switch between two layouts, the currently visible cell doesn't adhere to the zIndex it's layout attributes has been set in layoutAttributesForItemAtIndexPath:.

For example, if I were to have a UICollectionView with UICollectionViewFlowLayout, set it's minimumLineSpacing to a negative number so the cells overlap and then set a zIndex on each cell higher than that of the previous cell, then it appears as if the cells are stacked from the bottom up.

However this breaks if I set the layout to another layout then back to that original layout. It's as if the currently visible cell doesn't listen the zIndex and is placed atop the other cells. If I scroll the cell offscreen then back on it is in the correct place.


I have had the same problem. Switching the layout will disregard the zIndex for the cell.

I have managed to make it "look right" by applying a translation on the z-axis like this:

attributes.transform3D = CATransform3DMakeTranslation(0, 0, indexPath.row);

But it is just a visual fix, if you try to click on the item you will realize that the zIndex is still wrong until it is recycled by scrolling it offscreen.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK