【发布时间】:2019-10-21 18:56:09
【问题描述】:
我有一个 CALayer 配置如下:
private func setup() {
guard let theLayer = self.layer as? CAGradientLayer else {
return;
}
theLayer.colors = [UIColor.red.cgColor, UIColor.blue.cgColor]
theLayer.locations = [0.0, 1.0]
theLayer.startPoint = CGPoint(x: 0, y: 0)
theLayer.endPoint = CGPoint(x: 1, y: 0)
theLayer.frame = self.bounds
}
我想根据用户输入值(在下面的代码中称为“值”)将其剪辑为矩形。我该怎么做?
override func draw(_ rect: CGRect) {
// Drawing code
let frame = CGRect(x: 0, y: 0, width: rect.width, height: rect.height * (1-value))
// How to clip or mask self.layer to above frame?
}
【问题讨论】:
标签: ios uiview core-animation calayer cagradientlayer