Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop animation of [UIView animateKeyframesWithDuration] with UIViewKeyframeAnimationOptionRepeat option

I want to add a heartbeat effect to my view , one way to do is use UIView's animation method as follow :

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

                          }];
}

the problem is : if i want to stop the animation in an action , for example , a Stop butotn tapped , how I can do .

I know I can realize the same effect by create CAKeyFrameAnimation and add it to the view' CALayer .But I want to know how to do with the UIView's animation method. Thanks.

like image 616
monjer Avatar asked Nov 24 '25 01:11

monjer


1 Answers

Try

[panel1.layer removeAllAnimations];

Hope this will help you.

like image 170
Naoto Yoshioka Avatar answered Nov 26 '25 18:11

Naoto Yoshioka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!