How to animate borderColor change in swift

后端 未结 5 1006
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 05:26

For some reason this isn\'t working for me:

let color = CABasicAnimation(keyPath: \"borderColor\")
color.fromValue = sender.layer.borderColor;
color.toValue          


        
5条回答
  •  渐次进展
    2021-01-18 05:58

    I don't know why, but for some reason calling:

    color.fromValue = sender.layer.borderColor
    

    doesn't work. The color isn't being read correctly or something. I changed it to:

    let color = CABasicAnimation(keyPath: "borderColor");
    color.fromValue = UIColor.greenColor().CGColor;
    color.toValue = UIColor.redColor().CGColor;
    color.duration = 2;
    color.repeatCount = 1;
    sender.layer.addAnimation(color, forKey: "color and width");
    

    And then things started working as expected.

提交回复
热议问题