How Do You CAKeyframeAnimation Scale?

后端 未结 4 1707
盖世英雄少女心
盖世英雄少女心 2020-12-28 10:02

I want to create an animation with several key frames. I want my Layer (a button in this case) to scale up to 1.5 then down to 0.5 then up to 1.2 then down to 0.8 then 1.0.<

4条回答
  •  一向
    一向 (楼主)
    2020-12-28 10:15

    transform.scale, anyone?

    let anim = CAKeyframeAnimation(keyPath: "transform.scale")
    anim.values = [0, 1, 0, 1, 0, 1, 0]
    anim.duration = 4.0
    
    smallView.layer.addAnimation(anim, forKey: "what")
    

    Totally unrelated, if you are gonna use floats in the values array, you must add them as NSNumbers, otherwise they'd just end up as 0s!

    anim.values = [0.0, 1.2, 0.9, 1.0].map { NSNumber(double: $0) }
    

提交回复
热议问题