【问题标题】:Scrolling UITableView mess with gradient滚动 UITableView 与渐变混乱
【发布时间】:2018-01-20 16:17:07
【问题描述】:

我的 TableViewController 上有一个自定义的 TableViewCell。 该单元格有一个 UIView,它变成了一个渐变,在底部显示黑色,在 UIView 顶部显示清晰(透明)的颜色。

应用加载时看起来不错,但是当我滚动时,渐变变得越来越黑,并且“淡化”本身变得更小并且更接近 UIView 的顶部。

我不知道如何让它保持最初加载应用时的状态。

这是我的代码:

let gradient = CAGradientLayer()
gradient.frame = cell.gradientView.bounds
let colour:UIColor = .black
gradient.colors = [colour.withAlphaComponent(0.0).cgColor,colour.cgColor]

cell.gradientView.layer.insertSublayer(gradient, at: 0)

【问题讨论】:

    标签: ios swift uitableview uiview


    【解决方案1】:

    在 awakeFromNib 中而不是在 cellForRow 中添加此代码,因为由于出队,渐变被多次添加到单元格中

       let gradient = CAGradientLayer()
        gradient.frame = cell.gradientView.bounds
        let colour:UIColor = .black
        gradient.colors = [colour.withAlphaComponent(0.0).cgColor,colour.cgColor]
        self.gradientView.layer.insertSublayer(gradient, at: 0)
    

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 2014-12-18
      • 2015-11-25
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多