1

我有一个 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 的内容属性设置为 UIImage 来使用资产重新创建相同的效果。有没有办法让bounds跟随的动画和阴影一样?

4

1 回答 1

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"];
于 2012-08-13T10:34:34.043 回答