abh*_*ran 1 objective-c ios uicollectionview swift tvos
检查下图.我需要强调聚焦细胞,使其高于细胞collectionView
.
我知道我必须改变zIndex
聚焦细胞.怎么做?
我需要逻辑.我的代码在objective-c
.
这是为了tvOS
但iOS
我认为代码也可以在这里工作.
小智 8
尝试手动申请layer.zPosition
成为子类的zIndex
in applyLayoutAttributes:
方法UICollectionViewCell
:
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
[super applyLayoutAttributes:layoutAttributes];
self.layer.zPosition = layoutAttributes.zIndex;
}
Run Code Online (Sandbox Code Playgroud)
您需要创建自定义集合视图流布局。根据集合视图的滚动位置或可见矩形计算 zIndex。示例类如下所示。
final class CustomCollectionViewLayout: UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes = super.layoutAttributesForElements(in: rect)
attributes?.forEach {
$0.zIndex = 0 //Compute and set
}
return attributes
}
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attribute = super.layoutAttributesForItem(at: indexPath)
attribute?.zIndex = 0 //Compute and set
return attribute
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4076 次 |
最近记录: |