ear*_*dly 8 uikit ios uicollectionview uicollectionviewcell
我试图实现的效果是一种粘性标题单元格.对我来说,粘性细胞漂浮在其他细胞的顶部是很重要的.有点像这样:
????????????
? ?
? Cell 0 ?
? ??
?????????????
? Cell 4 ?
? ?
????????????
????????????
? ?
? Cell 5 ?
? ?
????????????
????????????
? ?
? Cell 6 ?
? ?
????????????
Run Code Online (Sandbox Code Playgroud)
单元格4,5和6通常是可见的,我正在构建UICollectionViewFlowLayout子类中单元格0的属性layoutAttributesForElementsInRect:.我所做的只是调用超级实现,确定我需要添加哪个单元格然后构造UICollectionViewLayoutAttributes(forCellWithIndexPath:).然后我将zIndex它设置为1(默认为0).
我得到的问题是UICollectionView似乎总是忽略了zIndex
????????????
? ?
? Cell 0 ?
?????????????
?? ?
? Cell 4 ?
? ?
????????????
????????????
? ?
? Cell 5 ?
? ?
????????????
????????????
? ?
? Cell 6 ?
? ?
????????????
Run Code Online (Sandbox Code Playgroud)
现在我相信可以使用3D变换在视觉上对其进行排序,但这对我不起作用,因为我不希望任何点击进入顶部的单元格.因此,在此示例中,我不希望Cell 4接收针对Cell 0的抽头.
有没有人有任何想法?这是在iOS 8.4上.
UICollectionViewLayoutAttributes.zIndex由于 UIKit 错误,更新不起作用。
这段代码可以解决问题:
// In your UICollectionViewCell subclass:
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
super.apply(layoutAttributes)
layer.zPosition = CGFloat(layoutAttributes.zIndex) // or any zIndex you want to set
}
Run Code Online (Sandbox Code Playgroud)
在UICollectionViewLayout中设置zIndex对我不起作用
我在UICollectionViewController的方法中设置zIndex
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
customCell.layer.zPosition = 0;
}
Run Code Online (Sandbox Code Playgroud)
我最好的猜测是在布局和控制器之间将zIndex设置为怪异的东西
我制作了一个独立的项目,以删除所有无关的代码。在这个过程中,我想我找到了自己的解决方案。
override func initialLayoutAttributesForAppearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes?
和
override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes?
我们并没有应用新的zIndex,所以我认为这就是造成它的原因。
只是想我应该发回解决方案,以防在搜索其他人时出现这种情况。
| 归档时间: |
|
| 查看次数: |
2636 次 |
| 最近记录: |