我知道我们需要使用CABasicAnimation来动画阴影,但是我不知道如何将UIViewPropertyAnimatorCABasicAnimation集成在一起。

最佳答案

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

我找到了解决方案。

10-08 03:16