如何使用UIViewKeyframeAnimationOptionRepeat选项停止[UIView animateKeyframesWithDuration]的动画

时间:2014-12-03 03:13:10

标签: animation uiview

我想在我的视图中添加一个心跳效果,一种方法是使用UIView的动画方法如下:

- (void)heartBeating
{
    UIView *panel;
    NSTimeInterval during = 0.8;
    [UIView animateKeyframesWithDuration:during delay:0.0
                             options:UIViewKeyframeAnimationOptionCalculationModeLinear|UIViewKeyframeAnimationOptionRepeat
                          animations:^{
                              [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.4 animations:^{
                                  panel.transform = CGAffineTransformMakeScale(1.2, 1.2);
                              }];
                              [UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.6 animations:^{
                                  panel.transform =CGAffineTransformIdentity ;
                              }];

                          } completion:^(BOOL finished) {

                          }];
}

问题是:如果我想在一个动作中停止动画,例如,一个Stop butotn轻敲,我该怎么做。

我知道我可以通过创建CAKeyFrameAnimation来实现相同的效果并将其添加到视图'CALayer。但我想知道如何处理UIView的动画方法。感谢。

1 个答案:

答案 0 :(得分:9)

尝试

[panel1.layer removeAllAnimations];

希望这会对你有所帮助。