我的tableView位于一个空白的内容视图中,其中有约束将其保持在原位。该表将在容器中正常运行,但是只要我使用下面的代码应用渐变,渐变就会完美地工作,除了我的tableViewCells的右侧被截断。它仅在应用渐变时发生。任何建议将不胜感激。
在添加Gradient之前,表视图如下所示:
TableView with full TableViewCells
添加渐变后,表视图如下所示:
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
}
我希望它对你有用。