I have a view on which I\'ve set the layerOpacity to 1.
theView.layer.shadowOpacity = 1.0;
This looks fine when the view is farther down th
I've put above code in a little extension of UIView:
extension UIView {
func animateLayer(_ keyPath: WritableKeyPath, to value:Value, duration: CFTimeInterval) {
let keyString = NSExpression(forKeyPath: keyPath).keyPath
let animation = CABasicAnimation(keyPath: keyString)
animation.fromValue = self.layer[keyPath: keyPath]
animation.toValue = value
animation.duration = duration
self.layer.add(animation, forKey: animation.keyPath)
var thelayer = layer
thelayer[keyPath: keyPath] = value
}
}
Usage like:
animateLayer(\.shadowOffset, to: CGSize(width: 3, height: 3), duration:1)
animateLayer(\.shadowOpacity, to: 0.4, duration: 1)
It's not thoroughly tested. but worked for me. (Also posted here)