gpt4 book ai didi

ios - 如何在 CALayer 中为图像制作动画

转载 作者:行者123 更新时间:2023-11-30 12:20:05 24 4
gpt4 key购买 nike

在我的CALayer中,我正在尝试对图像进行动画处理,但动画层没有显示。我在这里做错了什么:

return CALayer().build {

let myLayer = CALayer()

let animation = CAKeyframeAnimation(keyPath: "contents")
animation.fillMode = kCAFillModeForwards
animation.duration = 3
animation.values = TimeLineVC.likeInteractionArray.map {
$0.cgImage as AnyObject
}
animation.repeatCount = 3

myLayer.frame = $0.bounds
myLayer.add(animation, forKey: "contents")
$0.insertSublayer(myLayer, above: $0)
myLayer.backgroundColor = UIColor.black.cgColor


}

最佳答案

添加一些属性后它对我有用:

let animation = CAKeyframeAnimation(keyPath: "contents")
animation.calculationMode = kCAAnimationDiscrete
animation.duration = 3.0
animation.repeatCount = .greatestFiniteMagnitude
animation.autoreverses = false
animation.values = TimeLineVC.likeInteractionArray.map {$0.cgImage!}
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.beginTime = 0.0
$0.add(animation, forKey: "contents")

关于ios - 如何在 CALayer 中为图像制作动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44898785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com