2014-12-03 71 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