首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS -停止重复的UIAnimation?

iOS -停止重复的UIAnimation?
EN

Stack Overflow用户
提问于 2012-03-18 07:43:10
回答 2查看 3.5K关注 0票数 4

我有一个动画需要重复,直到我决定停止它。

单击按钮后如何在动画中停止?

代码语言:javascript
复制
[UIView animateWithDuration:0.2 delay:0 options:(UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) animations:^{

        CGAffineTransform transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(5));
        self.transform = transform;

    }  completion:^(BOOL finished){

    }];
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-06 18:25:03

你可以使用CABasicAnimation来代替。

代码语言:javascript
复制
    CABasicAnimation *appDeleteShakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
appDeleteShakeAnimation.autoreverses = YES;
appDeleteShakeAnimation.repeatDuration = HUGE_VALF;
appDeleteShakeAnimation.duration = 0.2;
appDeleteShakeAnimation.fromValue = [NSNumber numberWithFloat:-degreeToRadian(5)];
appDeleteShakeAnimation.toValue=[NSNumber numberWithFloat:degreeToRadian(5)];
[self.layer addAnimation:appDeleteShakeAnimation forKey:@"appDeleteShakeAnimation"];

然后当你想停止它的时候,你可以直接打电话给

代码语言:javascript
复制
[self.layer removeAnimationForKey:@"appDeleteShakeAnimation"];
票数 2
EN

Stack Overflow用户

发布于 2013-03-04 20:41:27

您必须添加另一个选项UIViewAnimationOptionAllowUserInteraction ...

你应该试试这个:

代码语言:javascript
复制
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^
{
    view.frame = CGRectMake(0, 100, 200, 200);
} completion:^(BOOL finished)
{
    if(! finished) return;
}];

要停止动画,请使用以下命令:

代码语言:javascript
复制
[view.layer removeAllAnimations];
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9754783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档