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

objective-c – 为CALayer阴影路径设置动画,第1张

概述我正在为CALayer制作阴影路径. 框架正确调整大小,但阴影不会缩放. 相反,阴影从最终大小CGSize(20,20)开始,并在整个动画中保持,即使我将shadowPath设置为初始值 [CATransaction begin];[CATransaction setAnimationDuration: 0];[CATransaction setDisableActions: TRUE]; 我正在为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

这个问题对我来说很难! 总结

以上是内存溢出为你收集整理的objective-c – 为CALayer阴影路径设置动画全部内容,希望文章能够帮你解决objective-c – 为CALayer阴影路径设置动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1251968.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存