ios – 使用Core Animation更改cornerRadius

前端之家收集整理的这篇文章主要介绍了ios – 使用Core Animation更改cornerRadius前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过以下方式更改按钮的角半径(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"];
原文链接:https://www.f2er.com/iOS/333159.html

猜你在找的iOS相关文章