Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tatsuro-ueda/3329871 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3329871 to your computer and use it in GitHub Desktop.
【アニメーション】CAレイヤーのドロップシャドウを本体が大きくなる時に一緒に大きくしたい

##Animating a CALayer shadowpath

At first, small square with drop shadow.

ss

When button pushed, square and shadow grow bigger together.

ss

The main code is below:

[CATransaction begin];
[CATransaction setAnimationDuration:5.0];
CAMediaTimingFunction *timing = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[CATransaction setAnimationTimingFunction:timing];
layer.frame = CGRectMake(0,0,100,100);
[CATransaction commit];    

CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"];
shadowAnimation.duration = 5.0;
shadowAnimation.fromValue = (id)[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 50, 50)].CGPath;
shadowAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)].CGPath;
[layer addAnimation:shadowAnimation forKey:@"shadow"];

You can download this project from GitHub and just run it.

https://github.com/weed/p120812_CALayerShadowTest

This question was very hard for me ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment