gpt4 book ai didi

ios - UICollectionView 不遵守 UICollectionViewLayoutAttributes 的 zIndex

转载 作者:可可西里 更新时间:2023-11-01 03:08:50 26 4
gpt4 key购买 nike

我想要达到的效果是一种粘性标题单元格。粘性细胞漂浮在其他细胞之上对我来说很重要。有点像这样:

┌──────────┐ 
│ │
│ Cell 0 │
│ ├┐
└┬─────────┘│
│ Cell 4 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 5 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 6 │
│ │
└──────────┘

单元格 4、5 和 6 通常是可见的,我在 layoutAttributesForElementsInRect: 期间在我的 UICollectionViewFlowLayout 子类中构建单元格 0 的属性。我所做的就是调用 super 实现,确定我需要添加到哪个单元格,然后构造 UICollectionViewLayoutAttributes(forCellWithIndexPath:)。然后,我将它的 zIndex 设置为 1(默认为 0)。

我遇到的问题是 UICollectionView 似乎总是忽略 zIndex

┌──────────┐ 
│ │
│ Cell 0 │
│┌─────────┴┐
└┤ │
│ Cell 4 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 5 │
│ │
└──────────┘
┌──────────┐
│ │
│ Cell 6 │
│ │
└──────────┘

现在我相信可以使用 3d 变换从视觉上解决这个问题,但这对我不起作用,因为我不希望任何点击进入顶部的单元格。因此,在此示例中,我不希望 Cell 4 接收用于 Cell 0 的抽头。

有人有什么想法吗?这是在 iOS 8.4 上。

最佳答案

由于 UIKit 错误,更新 UICollectionViewLayoutAttributes.zIndex 不起作用。

这段代码可以解决问题:

// In your UICollectionViewCell subclass:
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
super.apply(layoutAttributes)
layer.zPosition = CGFloat(layoutAttributes.zIndex) // or any zIndex you want to set
}

关于ios - UICollectionView 不遵守 UICollectionViewLayoutAttributes 的 zIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31697578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com