objective-c – 为CALayer阴影路径设置动画

我正在为CALayer制作阴影路径.

框架正确调整大小,但阴影不会缩放.

相反,阴影从最终大小CGSize(20,20)开始,并在整个动画中保持,即使我将shadowPath设置为初始值

[CATransaction begin];
[CATransaction setAnimationDuration: 0];
[CATransaction setdisableActions: TRUE];
    layer.frame = CGRectMake(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,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,100,100);
[CATransaction commit];    

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

您可以从GitHub下载此项目并运行它.

https://github.com/weed/p120812_CALayerShadowTest

这个问题对我来说很难!

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...