Animating CALayer's shadowPath property

后端 未结 3 691
滥情空心
滥情空心 2020-12-10 05:16

I am aware that a CALayer\'s shadowPath is only animatable using explicit animations, however I still cannot get this to work. I suspect that I am not passing the toVa

3条回答
  •  隐瞒了意图╮
    2020-12-10 05:30

    let cornerRadious = 10.0
            //
            let shadowPathFrom = UIBezierPath(roundedRect: rect1, cornerRadius: cornerRadious)
            let shadowPathTo = UIBezierPath(roundedRect: rect2, cornerRadius: cornerRadious)
            //
            layer.masksToBounds = false
            layer.shadowColor = UIColor.yellowColor().CGColor
            layer.shadowOpacity = 0.6
            //
            let shadowAnimation = CABasicAnimation(keyPath: "shadowPath")
            shadowAnimation.fromValue = shadowPathFrom.CGPath
            shadowAnimation.toValue = shadowPathTo.CGPath
            shadowAnimation.duration = 0.4
            shadowAnimation.autoreverses = true
            shadowAnimation.removedOnCompletion = true
            shadowAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            layer.addAnimation(shadowAnimation, forKey: "shadowAnimation")
    

提交回复
热议问题