ios - 将 UIView 的 CALayer 动画化为圆角

标签 ios animation core-animation rounded-corners catransition

我正在尝试为我的 View 角设置动画。 cornerRadius 属性被列为可动画的,但我似乎无法让它工作。实际上,我也无法获得任何其他属性来制作动画,但角落是我感兴趣的。这是我的代码,它非常简单:

[CATransaction begin];
[CATransaction setValue: [NSNumber numberWithFloat: 2.0f] forKey:kCATransactionAnimationDuration];

self.myView.layer.cornerRadius = 50.0f;

[CATransaction commit];

伙计们,我在这里错过了什么?角变圆了,但它是瞬时的,而不是需要 2 秒。

最佳答案

CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim1.fromValue = [NSNumber numberWithFloat:0.0f];
anim1.toValue = [NSNumber numberWithFloat:50.0f];
anim1.duration = 2.0;
[self.myView.layer addAnimation:anim1 forKey:@"cornerRadius"];

关于ios - 将 UIView 的 CALayer 动画化为圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5886915/

相关文章:

html - 使用CSS从左到右创建动画的最佳方式

cocoa-touch - 在 CALayer 中使用 Core Graphics 绘图

ios - CAShapeLayer 动画的完成 block

ios - 使用 mailto : URLs 发送电子邮件

iphone - 在 iOS 中创建可平移的 3D 空间

android - Flutter:找不到符号 MethodCallHandler

ios - iOS 中 Core Animation 和 UIKit Dynamics 的区别

ios - 更改 UISearchBar 的字体大小

ios - 使用自动布局时 UIView 框架重置

android - 动画android后按钮不起作用