2017-07-04 44 views
0

在我的CALayer中,我嘗試製作動畫圖像,但動畫層未顯示出來。我在做什麼錯在這裏:如何在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 


     } 

回答

0

它增加了一些特性後,爲我工作:

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