sud*_*all 7 ios uicollectionview uicollectionviewcell swift
如果我cellForItemAtIndexPath
按如下方式设置单元格的alpha属性...
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("CGPathCell", forIndexPath: indexPath) as UICollectionViewCell
// Prepare cell
cell.alpha = 0.5
cell.setNeedsDisplay()
return cell
}
Run Code Online (Sandbox Code Playgroud)
...最初出现的细胞是不透明的(α为1.0).如果我滚动,出现的"新"(重用)单元格具有预期的alpha值.如果我滚动回到开头,"原始"单元格(开始不透明)现在也具有预期的alpha值.
为什么在初始加载时未设置alpha值?
其他不起作用的尝试:
将此添加到委托,我得到相同的结果:
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
cell.alpha = 0.5
}
Run Code Online (Sandbox Code Playgroud)将此添加到cellForItemAtIndexPath
:
let attrs = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
attrs.alpha = 0.5
cell.applyLayoutAttributes(attrs)
Run Code Online (Sandbox Code Playgroud)我相信这种情况正在发生,因为Apple正在对细胞进行一些特殊的内部处理UICollectionView
.如果在单元格的contentView
属性上设置alpha ,则alpha会按预期保持不变.
该UICollectionViewCell文档 样的暗示在此:
要配置单元格的外观,请将显示数据项内容所需的视图添加为contentView属性中视图的子视图.不要直接将子视图添加到单元格本身.
如果您有backgroundView
或selectedBackgroundView
,则需要单独设置其alpha.
前段时间我在调整pdf大小时遇到了类似的问题,可能是一样的。我用以下方式解决了这个问题,每次必须调整pdf大小时setNeedsDisplay不起作用,所以我制作了一个ViewController,其alpha:0并调用一个非动画segue到该视图控制器,以便清晰的视图控制器是在我想要更新的视图控制器上,此后我立即关闭了新的视图控制器,因此 pdf 被更新为新的大小。这个问题也很老了,也许这可以帮助你解决你的问题。
归档时间: |
|
查看次数: |
1877 次 |
最近记录: |