KelvinJin / AnimatedCollectionViewLayout

A UICollectionViewLayout subclass that adds custom transitions/animations to the UICollectionView without effecting your existing code.
MIT License
4.7k stars 347 forks source link

On vertical scroll with sections, unexpected behaviour. Cells appear in front of others #64

Open Johnathan-Aretos opened 3 years ago

Johnathan-Aretos commented 3 years ago

When sections are being used it breaks the logic

attributes.zIndex = attributes.indexPath.row -> PageAttributeAnimator.swift

Given a zIndex will determine depth when using indexPath values e.g [0,1], sections, row respectively. We run into issues when the section resets.

I don't know of a cleaner solution, but what I've been using at the moment is

var section = attributes.indexPath.section
var numItems = 0

while section >= 0 {
    numItems += collectionView.numberOfItems(inSection: section)
    section -= 1

attributes.zIndex = attributes.indexPath.row + numItems

Which seems to be doing the trick, my run into performance issues when using larger data sets. A more elegant solution will be to use visible cells and work out within the two cells an appropriate zIndex.

Happy for suggestions to make a PR