gpt4 book ai didi

ios - CAL层裁剪

转载 作者:行者123 更新时间:2023-11-29 05:41:54 25 4
gpt4 key购买 nike

我的 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?
}

最佳答案

将图层嵌入到具有适当frame的容器图层中,并将其masksToBounds属性设置为true

关于ios - CAL层裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56474463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com