应用渐变蒙版时 TableViewCell 的一侧被切断

Side of TableViewCell gets cut off when applying a gradient mask

我的 tableView 位于一个空白的内容视图中,并有约束将其固定到位。 table 将在容器中自行正常运行,但只要我使用下面的代码应用渐变,渐变就可以完美运行,除了我的 tableViewCells 的右侧被切断。它仅在应用渐变时发生。如有任何建议,我们将不胜感激。

添加渐变之前,table 视图如下所示:

TableView with full TableViewCells

添加渐变后,table 视图如下所示:

TableView with cut TableViewCells

这是我用来应用渐变的代码。

        let gradientLayerMask = CAGradientLayer()
    gradientLayerMask.frame = gradientMask.bounds
    gradientLayerMask.colors = [UIColor.clear.cgColor, UIColor.white.cgColor, UIColor.white.cgColor, UIColor.clear.cgColor]
    gradientLayerMask.locations = [0.0,0.1,0.9,1.0]

    gradientMask.layer.mask = gradientLayerMask

    exerciseTable.contentInset = UIEdgeInsets(top: 15, left: 0, bottom: 0, right: 0)

为渐变代码设置一些延迟

func delay(time: Double, closure:
    @escaping ()->()) {

    DispatchQueue.main.asyncAfter(deadline: .now() + time) {
        closure()
    }

}

这样使用。

delay(time: 0.2) {
    //gradient code
}

希望对你有用。