ios – 使用Core Animation更改cornerRadius

ios – 使用Core Animation更改cornerRadius,第1张

概述我试图通过以下方式更改按钮的角半径(OpenNoteVisible.layer): CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];animation.timingFunction = [CAMediaTimingFunction functionWithName: 我试图通过以下方式更改按钮的角半径(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全部内容,希望文章能够帮你解决ios – 使用Core Animation更改cornerRadius所遇到的程序开发问题。

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

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

原文地址:https://www.54852.com/web/1102777.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存