CABasicAnimation动画但视图框架不是持久的

时间:2014-02-10 01:36:35

标签: cabasicanimation caanimation

我今天一直在玩CABasicAnimation和CAAnimationGroup,我已经爱上了它。我发生了几个基本动画,其中圆形缩小并缩小到圆角方形,就像iOS 7中的“语音备忘录”应用程序一样。

以下是代码。

CABasicAnimation *corner = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
corner.timingFunction = [CAMediaTimingFunction     functionWithName:kCAMediaTimingFunctionLinear];
corner.fromValue = [NSNumber numberWithFloat:recordingShape.layer.cornerRadius];
corner.toValue = [NSNumber numberWithFloat:30.0f];
corner.duration = 1.0;


//shrinking - scaling
CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = [NSNumber numberWithDouble:0.5];
shrink.duration = 0.5;


// Two animations concurrently so set up CAAnimationGroup
CAAnimationGroup *group = [CAAnimationGroup animation];
[group setDuration:0.5];
[group setAnimations:[NSArray arrayWithObjects:shrink, corner, nil]];

// Animate the layer
[[recordingShape layer] addAnimation:group forKey:@"bounceAndFade"];

动画按照预期很好地发生,但是在动画之后它会回到原来的圆形状态,任何人都可以指导我如何坚持图层的框架?

感谢。

1 个答案:

答案 0 :(得分:0)

好吧我不知道你可以为CAAnimationGroup组设置一个委托,因此我改变了实际的cornerRadius并在animationDidStop调用时进行了转换。