How do I animate opacity using swift?

后端 未结 4 1939
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 02:00

Could someone please provide me with an example of animating the opacity of an Image View in swift??

I couldn\'t even find a good example in objective c



        
4条回答
  •  萌比男神i
    2021-01-18 02:41

    You can also write it like this:

    animation.fromValue = 0.0
    animation.toValue = 1.0
    

    The whole code should be like this:

    let animation = CABasicAnimation(#keyPath(CALayer.opacity))
    animation.fromValue = 0.0
    animation.toValue = 1.0
    animation.duration = 1.0
    animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
    element.layer?.addAnimation(animation, forKey: "fade")
    

提交回复
热议问题