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 に答える