【问题标题】:Swift- animate CAshapeLayer stroke colorSwift-动画 CAshapeLayer 描边颜色
【发布时间】:2014-10-28 09:17:18
【问题描述】:

我正在尝试找到一种方法来为我正在创建的笔画的颜色设置动画

circleLayer = CAShapeLayer()
circleLayer.path = circlePath.CGPath
circleLayer.lineCap =  kCALineCapRound
circleLayer.fillColor = UIColor.clearColor().CGColor
CABasicAnimation fill = CABasicAnimation.
circleLayer.strokeColor = UIColor(red: 0.4, green: 1.0, blue: 0.2, alpha: 0.5).CGColor
circleLayer.lineWidth = 20.0;
circleLayer.lineJoin = kCALineJoinRound
// Don't draw the circle initially
circleLayer.strokeEnd = 0.0

// Add the circleLayer to the view's layer's sublayers
layer.addSublayer(circleLayer) 

我想要实现的是:当它被创建时(我在 1 秒的时间内创建它),颜色会自动生成动画。

【问题讨论】:

  • 这看起来与您之前的问题 stackoverflow.com/questions/26602171/… 完全相同。如果您没有得到答案,请尝试改进问题,提供更多信息,......但不要简单地重复。
  • @MartinR 我教它被删除了哦。我可以删除这个马丁吗?

标签: swift uicolor uianimation cashapelayer stroke


【解决方案1】:

找到解决方案。享受。当然,在创建 CAShapeLayer 之后:

        let animcolor = CABasicAnimation(keyPath: "strokeColor")
        animcolor.fromValue         = UIColor.greenColor().CGColor
        animcolor.toValue           = UIColor.orangeColor().CGColor
        animcolor.duration          = 1.0;
        animcolor.repeatCount       = 0;
        animcolor.autoreverses      = true
        circleLayer.addAnimation(animcolor, forKey: "strokeColor")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多