2014-12-03 82 views
3

我想心跳效果添加到我的观点,其中一个办法就是使用的UIView的动画方法如下:如何使用UIViewKeyframeAnimationOptionRepeat选项停止[UIView的animateKeyframesWithDuration]动画

- (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) { 

          }]; 
} 

的问题是:如果我想在动作中停止动画,例如,点击停止butotn,我该怎么做。

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

回答

9

尝试

[panel1.layer removeAllAnimations]; 

希望这会帮助你。

+0

的作品。谢谢! – 2015-06-05 13:42:04