我有3个CABasicAnimation的3个颜色条,这是一个接一个。在第三个完成后,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];
}
}那么你知道我在这里做错了什么吗?知道如何修复它吗?谢谢你!!
发布于 2014-01-26 08:35:00
有一种方法可以暂停和恢复任何动画。如果我理解正确的话,这里有几个很好的字符串可以帮助你
- (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;
}https://stackoverflow.com/questions/21357209
复制相似问题