CoreAnimation - Opacity Fade In and Out Animation Not Working

后端 未结 11 1923
悲&欢浪女
悲&欢浪女 2020-12-08 05:02

I\'m attempting to create a fairly simple CoreAnimation for use in an AVComposition. My goal is to create a CALayer which, through various sublayer

11条回答
  •  情书的邮戳
    2020-12-08 05:57

    The point is key name. You have to set the opacity key.

    layer.add(animation, forKey: nil)         // Not Working
    layer.add(animation, forKey: "opacity")   // Working
    

    Check the sample code. I tested in Swift 4

        let animation                   = CAKeyframeAnimation()
        animation.duration              = 1.53
        animation.autoreverses          = false
        animation.keyTimes              = [0, 0.51, 0.85, 1.0]
        animation.values                = [0.5, 0.5, 1.0, 0.5]
        animation.beginTime             = 0
        animation.isRemovedOnCompletion = false
        animation.fillMode              = kCAFillModeBoth
        animation.repeatCount           = .greatestFiniteMagnitude
        layer.add(animation, forKey: "opacity")
    

提交回复
热议问题