首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios - cabasicanimation需要重置

ios - cabasicanimation需要重置
EN

Stack Overflow用户
提问于 2014-01-26 06:43:03
回答 1查看 320关注 0票数 1

我有3个CABasicAnimation的3个颜色条,这是一个接一个。在第三个完成后,3个酒吧将留在他们的最终位置。在此之前,一切都很好,以下是代码:

代码语言:javascript
复制
- (void)animationDidStop:(CABasicAnimation *)theAnimation finished:(BOOL)flag {
    NSString* value = [theAnimation valueForKey:@"id"];
    if([value isEqualToString:@"position1"]){
        [self playVideoAtIndex:1];
    }
    else if([value isEqualToString:@"position2"]){
        [self playVideoAtIndex:2];
    }
    else if([value isEqualToString:@"position3"]){

    }
}

在此之前,我创建了3个这样的动画:

代码语言:javascript
复制
-(void)createAnimationAtIndex:(NSInteger)index{
UILabel *label = (UILabel *)[barLabelArray objectAtIndex:index];
if(index==0){
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.delegate = self;
    //SOMETHING HERE
    [label.layer addAnimation:animation forKey:@"position1"];
}
else if(index==1){
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.delegate = self;
    //SOMETHING HERE
    [self.delegate startPlayVideoAtIndex:1];
    [label.layer addAnimation:animation forKey:@"position2"];
}
else if(index==2){
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.delegate = self;
    //SOMETHING HERE
    [label.layer addAnimation:animation forKey:@"position3"];
}

}

因此,如果我等待所有动画停止,当我返回时,它们将再次正常启动动画。但有时我需要在中间停止动画。然后当我回来重新开始动画时,一切都搞乱了。下面是停止动画的代码:

代码语言:javascript
复制
-(void)reset{
    for(UILabel *label in barLabelArray){
        [label.layer removeAllAnimations];
    }
}

那么你知道我在这里做错了什么吗?知道如何修复它吗?谢谢你!!

EN

回答 1

Stack Overflow用户

发布于 2014-01-26 08:35:00

有一种方法可以暂停和恢复任何动画。如果我理解正确的话,这里有几个很好的字符串可以帮助你

代码语言:javascript
复制
- (void) pauseLayer
{
    CFTimeInterval pausedTime = [label.layer convertTime:CACurrentMediaTime() fromLayer:nil];
    label.layer.speed = 0.0;
    label.layer.timeOffset = pausedTime;
}

- (void) resumeLayer
{
    CFTimeInterval pausedTime = [label.layer timeOffset];
    label.layer.speed = 1.0;
    label.layer.timeOffset = 0.0;
    label.layer.beginTime = 0.0;
    CFTimeInterval timeSincePause = [label.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
    label.layer.beginTime = timeSincePause;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21357209

复制
相关文章

相似问题

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