【问题标题】:CALayer clippingCALayer 裁剪
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 2022-01-23
      • 2020-12-25
      • 2015-08-18
      • 1970-01-01
      相关资源
      最近更新 更多