gpt4 book ai didi

ios - 使用 Core Animation 改变 cornerRadius

转载 作者:可可西里 更新时间:2023-11-01 03:25:22 29 4
gpt4 key购买 nike

我正在尝试通过以下方式更改按钮 (OpenNoteVisible.layer) 的角半径:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSNumber numberWithFloat:10.0f];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.duration = 1.0;
[animation.layer setCornerRadius:140.0];
[OpenNoteVisible.layer addAnimation:animation forKey:@"cornerRadius"];

但是这段代码在行 [animation.layer setCornerRadius:140.0] 处给出了一个错误;我不明白为什么。我已经导入了 Quartz 核心框架。

最佳答案

您正在动画对象的图层属性上设置圆角半径;此动画对象没有图层属性。

您需要在要设置动画的对象的图层上设置圆角半径,在本例中为 OpenNoteVisible。您还需要确保动画对象的 toValue 与您在图层上设置的值匹配,否则您会得到奇怪的动画。

您的代码现在应该是:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSNumber numberWithFloat:10.0f];
animation.toValue = [NSNumber numberWithFloat:140.0f];
animation.duration = 1.0;
[OpenNoteVisible.layer setCornerRadius:140.0];
[OpenNoteVisible.layer addAnimation:animation forKey:@"cornerRadius"];

关于ios - 使用 Core Animation 改变 cornerRadius,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18511359/

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