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

mon*_*jer 3 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) {

                          }];
}
Run Code Online (Sandbox Code Playgroud)

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

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

小智 9

尝试

[panel1.layer removeAllAnimations];
Run Code Online (Sandbox Code Playgroud)

希望这会帮助你.