func updateValueFromPresentationLayer(forAnimation anim: CAAnimation!, theLayer : CALayer){
if let basicAnim = anim as? CABasicAnimation{
theLayer.setValue(theLayer.presentation()?.value(forKeyPath: basicAnim.keyPath!), forKeyPath: basicAnim.keyPath!)
}else if let keyAnim = anim as? CAKeyframeAnimation{
theLayer.setValue(theLayer.presentation()?.value(forKeyPath: keyAnim.keyPath!), forKeyPath: keyAnim.keyPath!)
}else if let groupAnim = anim as? CAAnimationGroup{
for subAnim in groupAnim.animations! as [CAAnimation]{
updateValueFromPresentationLayer(forAnimation: subAnim, theLayer: theLayer)
}
}
}
