ios - UICollectionViewLayout doesn't update zIndex when changing layouts -


i have 2 uicollectionviewlayouts work fine when used on own when switching between 2 layouts using setcollectionviewlayout:animated: zindex of layout being animated doesn't use own zindex values, instead uses zindex values of original layout.

here 2 layouts on own:

in layout 1 cells stacked item 0 on top.

enter image description here

in layout 2 cells stacked item 0 on bottom.

enter image description here

in layout 1 set zindex with:

[attributes setzindex:100 - [indexpath item]]; 

in layout 2 set zindex with:

[attributes setzindex:100 + [indexpath item]]; 

if start layout 1 , change layout 2 end this:

enter image description here

if start layout 2 , change layout 1 end this:

enter image description here

i've experimented setting zindex in both layoutattributesforelementsinrect: , layoutattributesforitematindexpath: , i've found when switching layouts, layoutattributesforelelmentsinrect: gets called once on layout being animated , layoutattributesforitematindexpath: gets called many times on both layouts animated transition happening.

i noticed calls layoutattributesforitematindexpath: being called on layout being animated after being called on layout being animated to. lead me try odd, set correct zindex given layout in layoutattributesforelementsinrect: set zindex other layout in layoutattributesforitematindexpath:. results in correct layout after animation completed in either direction animation layout 2 layout 1 looks bad because zindex doesn't update till end of animation.

here looks right before animation layout 2 layout 1 completes (and corrects zindex):

enter image description here

to deal seeing in between state considering making intermediate layout changes zindex of cells in layout 2 before transitions layout 1. not elegant think may work if use setcollectionviewlayout:animated:completion: call setcollectionviewlayout:animated: inside completion block of first layout change.

anyway, seems crazy me should have set zindex opposite layout in layoutattributesforitematindexpath: in order correct end result of changing layouts. have suggestions how implement in way doesn't require hack?

edit implemented intermediate layout when switching layout 2 layout 1. intermediate layout different in regards zindex being flipped. interesting note switch between layout 2 , intermediate layout did not need apply hack in layoutattributesforitematindexpath: did need call reloaddata on collectionview in completion block of setcollectionviewlayout:animated:completion work.

would still love know why zindex hack necessary correctly switch other layouts.

without going details of uicollectionview architecture , layout methods, here conceptual idea:

given reusable cell recycle - not assign new content to cells in correct position*? is, make sure top cell has item 0 in 1 layout has last item in second layout. maybe involved reversing order seems more obvious , less complicated arithmetically recalculating z-index.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -