我正在为CALayer
的阴影路径设置动画。
框架可以正确调整大小,但是阴影无法缩放。
相反,即使我将shadowPath设置为初始值,阴影也从最终大小CGSize(20,20)
开始并保留在整个动画中
[CATransaction begin];
[CATransaction setAnimationDuration: 0];
[CATransaction setDisableActions: TRUE];
layer.frame = CGRectMake(0,0,10,10);
layer.shadowPath = [UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
[CATransaction commit];
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:10] forKey:kCATransactionAnimationDuration];
layer.frame = CGRectMake(0,0,20,20);
layer.shadowPath = [UIBezierPath bezierPathWithRect:tile.bounds].CGPath;
[CATransaction commit];
最佳答案
首先,带有阴影的小方块。
按下按钮时,正方形和阴影会一起变大。
主要代码如下:
[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"];
您可以从GitHub下载此项目,然后运行它。
https://github.com/weed/p120812_CALayerShadowTest
这个问题对我来说很难! :)
关于objective-c - 动画CALayer阴影路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11919001/