0

我有一个 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]; 行出现错误。

4

0 回答 0