func updateValueFromAnimations(forLayers layers: [CALayer]){
CATransaction.begin()
CATransaction.setDisableActions(true)

for aLayer in layers{
if let keys = aLayer.animationKeys(){
for animKey in keys{
let anim = aLayer.animation(forKey: animKey)
updateValue(forAnimation: anim!, theLayer: aLayer);
}
}

}

CATransaction.commit()
}

func updateValue(forAnimation anim: CAAnimation, theLayer : CALayer){
if let basicAnim = anim as? CABasicAnimation{
if (!basicAnim.autoreverses) {
theLayer.setValue(basicAnim.toValue, forKeyPath: basicAnim.keyPath!)
}
}else if let keyAnim = anim as? CAKeyframeAnimation{
if (!keyAnim.autoreverses) {
theLayer.setValue(keyAnim.values?.last, forKeyPath: keyAnim.keyPath!)
}
}else if let groupAnim = anim as? CAAnimationGroup{
for subAnim in groupAnim.animations! as [CAAnimation]{
updateValue(forAnimation: subAnim, theLayer: theLayer);

}
}
}
