gpt4 book ai didi

ios - cabasicanimation 需要重置

转载 作者:行者123 更新时间:2023-11-29 12:55:11 25 4
gpt4 key购买 nike

我有 3 个颜色条的 3 个 CABasicAnimation,它们相互跟随。第三个完成后,3 个小节将停留在其最终位置。到这里为止,一切都很好,这是代码:

- (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 个这样的动画:

-(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"];
}

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

-(void)reset{
for(UILabel *label in barLabelArray){
[label.layer removeAllAnimations];
}
}

那么你知道我在这里做错了什么以及如何解决它吗?谢谢!!

最佳答案

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

- (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;
}

关于ios - cabasicanimation 需要重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21357209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com