2012-08-13 46 views
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跟隨陰影一樣的動畫?

回答

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"];