UICollectionView setLayout:animated:不保留zIndex [英] UICollectionView setLayout:animated: not preserving zIndex

查看:120
本文介绍了UICollectionView setLayout:animated:不保留zIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当在UICollectionView中调用setLayout:animated在两种布局之间切换时,当前可见的单元格不遵守zIndex,它的布局属性已在layoutAttributesForItemAtIndexPath:中设置.

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:.

例如,如果我要把UICollectionViewUICollectionViewFlowLayout一起设置,请将它的minimumLineSpacing设置为负数,以便单元格重叠,然后在每个单元格上将zIndex设置为比上一个单元格更高的zIndex ,则好像电池是从下向上堆叠一样.

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.

但是,如果我将布局设置为其他布局,然后又恢复为原始布局,则此操作会中断.好像当前可见的单元格不侦听zIndex,而是放置在其他单元格的顶部.如果我在屏幕外滚动单元,则应将其放回正确的位置.

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.

推荐答案

我遇到了同样的问题.切换布局将忽略该单元格的zIndex.

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

通过在z轴上像这样进行平移,我设法使其看起来正确":

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);

但这只是一个视觉修复,如果您尝试单击该项目,您将意识到zIndex仍然是错误的,直到通过在屏幕外滚动将其回收为止.

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.

这篇关于UICollectionView setLayout:animated:不保留zIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆