我有一个CALayer的动画阴影路径:
CABasicAnimation* shadowAnimation = [CABasicAnimation animationWithKeyPath: @"shadowPath"];
shadowAnimation.duration = duration;
shadowAnimation.timingFunction = function;
shadowAnimation.fromValue = (id) panelView.layer.shadowPath;
panelView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect: CGRectSetOriginM20 (panelView.bounds, CGPointZero) cornerRadius: cornerRadius].CGPath;
[panelView.layer addAnimation: shadowAnimation forKey: @"shadow"];
panelView.layer.shadowOpacity = 1.0;
我需要通过将CALayer的content属性设置为UIImage来使用资源重新创建相同的效果。有没有办法让bounds
遵循与阴影相同的动画?
答案 0 :(得分:1)
不,您无法使内容遵循阴影路径。
相反,您必须将阴影路径和边界设置为动画。这可以在动画组中完成,这样您就可以在组上配置计时功能和持续时间。
CAAnimationGroup* shadowAndBounds = [CAAnimationGroup animation];
shadowAndBounds.duration = duration;
shadowAndBounds.timingFunction = function;
CABasicAnimation* shadowAnimation = [CABasicAnimation animationWithKeyPath: @"shadowPath"];
// Set to and from value for the shadow path ...
CABasicAnimation* boundsAnimation = [CABasicAnimation animationWithKeyPath: @"bounds"];
// Set to and from value for the bounds ...
shadowAndBounds.animations = @[ shadowAnimation, boundsAnimation ];
[panelView.layer addAnimation: shadowAndBounds forKey: @"shadowAndBounds"];