我有一个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
}我想根据用户输入值(在下面的代码中称为' value‘)将其裁剪到一个rect。我该怎么做呢?
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?
}发布于 2019-07-01 07:46:47
将该层嵌入到具有适当frame的容器层中,并将其masksToBounds属性设置为true。
https://stackoverflow.com/questions/56474463
复制相似问题