1
所以我有,我有UIBezierPath画一个圆,我需要设置上海华能与我的圈子一样,这里是我的代码:设置图层蒙版UIBezierPath上海华
override func draw(_ rect: CGRect) {
let circlePath = UIBezierPath(arcCenter: CGPoint(x: rect.midX, y: rect.midY), radius: circleRadius, startAngle: 0.0, endAngle:CGFloat(Double.pi * 2), clockwise: true)
let strokeColorAnimation = CABasicAnimation(keyPath: "strokeColor")
let strokeEndAnimation = CABasicAnimation(keyPath: "strokeEnd")
shapeLayer.path = circlePath.cgPath
shapeLayer.lineWidth = 0.3 * circleRadius
shapeLayer.fillColor = UIColor.clear.cgColor
if oldColor == nil { oldColor = newColor }
if oldStrokeEnd == nil { oldStrokeEnd = 0.01 * currentCGFloatProximity }
strokeColorAnimation.fromValue = oldColor!.cgColor
strokeColorAnimation.toValue = newColor.cgColor
strokeColorAnimation.duration = 0.3
strokeColorAnimation.isRemovedOnCompletion = false
strokeColorAnimation.fillMode = kCAFillModeForwards
strokeEndAnimation.fromValue = oldStrokeEnd
strokeEndAnimation.toValue = 0.01 * currentCGFloatProximity
strokeEndAnimation.duration = 0.3
strokeEndAnimation.isRemovedOnCompletion = false
strokeEndAnimation.fillMode = kCAFillModeForwards
shapeLayer.add(strokeColorAnimation, forKey: strokeColorAnimation.keyPath)
shapeLayer.add(strokeEndAnimation, forKey: strokeEndAnimation.keyPath)
layer.mask = shapeLayer
// layer.addSublayer(shapeLayer)
oldColor = newColor
oldStrokeEnd = 0.01 * currentCGFloatProximity
}
这里的时候,我加入上海华盈的是层光掩膜我shapeLayer我得到这样的结果,它是黑色,不改变它的颜色:当我添加子层上海华盈的层我得到这样的结果
//layer.mask = shapeLayer
layer.addSublayer(shapeLayer)
我想要的只是第一张图片的结果,但带有彩色圆圈。希望得到帮助。对不起我的英语不好。