动画setCornerRadius函数IOS

时间:2013-08-29 12:21:40

标签: ios caanimation

我有一个UIButton,我正在使用动画以这种方式改变它的大小:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options: UIViewAnimationCurveEaseInOut
                 animations:^{

                     OpenNoteVisible.frame = CGRectMake(20, 90, 260, 260);
                     [OpenNoteVisible.layer setCornerRadius:135.0f];

                 }
                 completion:^(BOOL finished){

                 }];

但是当我这样做时,我希望角半径从原来的40逐渐增加到135.问题是应用程序立即设置半径,而不是像按钮的大小那样逐渐改变它。我怎样才能获得这种效果?

编辑:

正如@ 0xfffffff建议的那样,我尝试使用此代码:

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];

0 个答案:

没有答案