如何停止核心动画? [英] how to stop core animation?

查看:89
本文介绍了如何停止核心动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在要在一定条件下使用核心动画为按钮制作动画,我想停止该动画如何停止动画?

I am animating a button using core animation now on a certain condition I want to stop that animation how do I stop the animation?

这里是制作动画的方法按钮

here is the method to animate the button

-(void)animateButton:(UIButton *)btnName
{
    CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulseAnimation.duration = .5;
    pulseAnimation.toValue = [NSNumber numberWithFloat:1.1];
    pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulseAnimation.autoreverses = YES;
    pulseAnimation.repeatCount = FLT_MAX;

    [btnName.layer addAnimation:pulseAnimation forKey:nil];
}


推荐答案

来自核心动画编程指南

开始和停止显式动画

您可以通过发送addAnimation:forKey:消息来开始显式动画。到目标层,将动画和标识符作为参数传递。一旦添加到目标图层,显式动画将一直运行,直到动画完成或将其从图层中删除为止。 用于将动画添加到图层的标识符还用于通过调用removeAnimationForKey:来停止动画。您可以通过向图层发送removeAllAnimations消息来停止该图层的所有动画。

You start an explicit animation by sending a addAnimation:forKey: message to the target layer, passing the animation and an identifier as parameters. Once added to the target layer the explicit animation will run until the animation completes, or it is removed from the layer. The identifier used to add an animation to a layer is also used to stop it by invoking removeAnimationForKey:. You can stop all animations for a layer by sending the layer a removeAllAnimations message.

这篇关于如何停止核心动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆