gpt4 book ai didi

ios - 使用核心动画为 StrokeColor 设置动画

转载 作者:可可西里 更新时间:2023-11-01 06:23:49 26 4
gpt4 key购买 nike

我正在尝试为 CAShapeLayar 的 strokeColor 属性设置动画。我查看了文档,并指出它是一个可动画的属性。该代码用于动画 postion.y 但不是 strokeColor。我很乐意获得任何帮助或建议

我用过的代码:

lyr.fillColor = [[UIColor clearColor] CGColor];
lyr.lineWidth = 3.8;
lyr.strokeColor = [[UIColor yellowColor] CGColor];
lyr.position = CGPointMake(160, 431);
lyr.anchorPoint = CGPointMake(.5f, .5f);
[self.view.layer addSublayer:lyr];

CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
basicAnimation.fromValue = [lyr valueForKey:@"strokeColor"];



basicAnimation.toValue =[NSValue valueWithPointer:[[UIColor clearColor] CGColor]];


basicAnimation.duration = 2;
basicAnimation.repeatCount = 10;
basicAnimation.autoreverses = YES;
[lyr addAnimation:basicAnimation forKey:@"strokeColor"];

提前致谢,或者。

最佳答案

这应该有效,因为我刚刚测试过它:

CABasicAnimation *strokeAnim = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; // I changed the animation pointer name, but don't worry.
basicAnimation.toValue = (id) [UIColor clearColor].CGColor; // Just get rid of the fromValue line, and just cast the CGColorRef to an id.
basicAnimation.duration = 2;
basicAnimation.repeatCount = 10;
basicAnimation.autoreverses = YES;
[lyr addAnimation:strokeAnim forKey:@"flashStrokeColor"]; // I like to name this key differently, so as not create confusion.

请注意,我从动画中删除了 fromValue 属性行,因为您需要与动画之前设置的 strokeColor 相同的值(它是多余的)。此外,我将 strokeColor 的 CGColorRef 转换为一个 id,这正是 toValue 属性想要的。

关于ios - 使用核心动画为 StrokeColor 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7080952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com