Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在CALayer中设置图像动画_Ios_Swift_Calayer - Fatal编程技术网

Ios 如何在CALayer中设置图像动画

Ios 如何在CALayer中设置图像动画,ios,swift,calayer,Ios,Swift,Calayer,在myCALayer中,我尝试为图像设置动画,但动画层未显示。我在这里做错了什么: return CALayer().build { let myLayer = CALayer() let animation = CAKeyframeAnimation(keyPath: "contents") animation.fillMode = kCAFillModeForwards animation.duration = 3

在my
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")