1
我有3個顏色條的3 CABasicAnimation,它們是相互跟隨的。三分之一完成後,3個酒吧將停留在最後的位置。直到這裏,什麼都好,這裏是代碼:ios - cabasicanimation需要重置
- (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];
}
}
那麼你知道我在做什麼錯在這裏,以及如何解決它?謝謝 !!