如何使用UIViewPropertyAnimator为视图图层阴影设置动画

时间:2017-01-09 08:42:02

标签: ios animation core-animation

我知道我们需要使用CABasicAnimation动画阴影,但我不知道如何整合UIViewPropertyAnimatorCABasicAnimation集成。

1 个答案:

答案 0 :(得分:0)

let shadowAnimation = CABasicAnimation(keyPath: "shadowOpacity")
shadowAnimation.fillMode = kCAFillModeForwards
shadowAnimation.isRemovedOnCompletion = false
shadowAnimation.fromValue = 0.3
shadowAnimation.toValue = 0
shadowAnimation.duration = transitionDuration

animator = UIViewPropertyAnimator(duration: transitionDuration, dampingRatio: 95, animations: {
    topShadowContainer.layer.add(shadowAnimation, forKey: "shadowOpacity")
}

我找到了解决方案。