UICollectionView 不遵守 UICollectionViewLayoutAttributes 的 zIndex [英] UICollectionView not obeying zIndex of UICollectionViewLayoutAttributes
问题描述
我想要达到的效果是一种粘性标题单元格.粘性细胞漂浮在其他细胞的顶部对我来说很重要.有点像这样:
The effect I'm trying to achieve is a kind of sticky header cell. It's important to me that the sticky cell floats over the top of the others. Something a bit like this:
┌──────────┐
│ │
│ Cell 0 │
│ ├┐
└┬─────────┘│
│ Cell 4 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 5 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 6 │
│ │
└──────────┘
单元格 4、5 和 6 通常是可见的,我正在 layoutAttributesForElementsInRect:
期间在我的 UICollectionViewFlowLayout
子类中构建单元格 0 的属性.我所做的就是调用超级实现,确定需要添加的单元格,然后构造UICollectionViewLayoutAttributes(forCellWithIndexPath:)
.然后我将它的 zIndex
设置为 1
(默认为 0
).
Cell 4, 5 and 6 would normally viewable and I'm constructing the attributes for cell 0 in my UICollectionViewFlowLayout
subclass during layoutAttributesForElementsInRect:
. All I do is call the super implementation, determine which cell I need to add in and then construct the UICollectionViewLayoutAttributes(forCellWithIndexPath:)
. I then set the zIndex
for it to 1
(default is 0
).
我遇到的问题是 UICollectionView
似乎总是忽略 zIndex
The problem I'm getting is that the UICollectionView
seems to always ignore the zIndex
┌──────────┐
│ │
│ Cell 0 │
│┌─────────┴┐
└┤ │
│ Cell 4 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 5 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 6 │
│ │
└──────────┘
现在我相信可以使用 3d 变换在视觉上对此进行排序,但这对我不起作用,因为我不希望任何点击进入顶部的单元格.因此,在此示例中,我不希望 Cell 4 接收针对 Cell 0 的抽头.
Now I believe it's possible to visually sort this out using a 3d transform, but that doesn't work for me as I don't want any taps going to the cell which is over the top. So in this example I don't want Cell 4 receiving taps intended for Cell 0.
有人有什么想法吗?这是在 iOS 8.4 上.
Does anyone have any ideas? This is on iOS 8.4.
推荐答案
我做了一个独立的项目,以去除我所有的无关代码.在这个过程中,我想我找到了自己的解决方案.
I made a standalone project in order to strip out all my extraneous code. In the process I think I found my own solution.
override func initialLayoutAttributesForAppearingItemAtIndexPath(itemIndexPath: NSIndexPath) ->UICollectionViewLayoutAttributes?
和override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) ->UICollectionViewLayoutAttributes?
也没有应用新的 zIndex
所以我认为这是导致它的原因.
were not also applying the new zIndex
so I think this was what was causing it.
只是想我应该发回解决方案,以防在搜索其他人时出现这种情况.
Just thought I should post back the solution in case this comes up in a search for anyone else.
这篇关于UICollectionView 不遵守 UICollectionViewLayoutAttributes 的 zIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!