2014-05-22 142 views
2

請不要參考CABasicAnimation returns to the original position before the next animationObjective-C - CABasicAnimation applying changes after animation?CABasicAnimation rotate returns to original position 我已經嘗試過了。CABasicAnimation在完成1個週期後回到其原始位置

below code does,bottom->top->goes left->back to it’s original position. 
bottom->top->goes left->back to its original position. 
I need bottom->top->goes left.bottom->top->goes left so on… 

-(void)addUpDownAnimationForButton:(UILabel*)label 
{ 
    CABasicAnimation * bottomAnimation ; 
    bottomAnimation =[CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; 
    [bottomAnimation setValue:@"animation1" forKey:@"id"]; 
    bottomAnimation.delegate = self; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)]; 
    bottomAnimation.duration = 2.0; 
    bottomAnimation.fromValue = [NSNumber numberWithFloat:13]; 
    bottomAnimation.toValue = [NSNumber numberWithFloat:-7]; 
    bottomAnimation.repeatCount = 0; 
    bottomAnimation.fillMode = kCAFillModeForwards; 
    bottomAnimation.removedOnCompletion = NO; 
    [btnSpecialForListing.titleLabel.layer addAnimation:bottomAnimation forKey:@"transform.translation.y"]; 
} 
- (void)animationDidStop:(CAAnimation *)theAnimation2 finished:(BOOL)flag 
{ 
    if([[theAnimation2 valueForKey:@"id"] isEqual:@"animation1"]) { 
     CABasicAnimation *moveAnimation; 
     moveAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
     moveAnimation.duration=3.5; 
     moveAnimation.repeatCount=0; 
     moveAnimation.autoreverses=NO; 
     moveAnimation.fromValue=[NSNumber numberWithFloat:0]; 
     moveAnimation.toValue=[NSNumber numberWithFloat:-400]; 
     moveAnimation.removedOnCompletion = NO; 
     moveAnimation.fillMode = kCAFillModeRemoved; 
     [btnSpecialForListing.titleLabel.layer addAnimation:moveAnimation forKey:@"transform.translation.x"]; 
    } 
} 

任何幫助將不勝感激。 謝謝!

回答

3

你試過嗎?

moveAnimation.fillMode = kCAFillModeForwards; 
moveAnimation.removedOnCompletion = NO; 

編輯 至於我可以看到你也可以使用animateWithDuration具有完成塊。 示例如下:

CGRect rect = btnSpecialForListing.titleLabel.frame; 
[UIView animateWithDuration:2.0 animations:^{ 

rect.origin.y = -7; 
btnSpecialForListing.titleLabel.frame = rect; 

} completion:^(BOOL finished){ 

[UIView animateWithDuration:3.5 animation:^{ 
rect.origin.x = -400; 
btnSpecialForListing.titleLabel.frame = rect; 
}]; 

}]; 
+0

是的,我做了。 但是在第一個循環完成之後,只有移動動畫才起作用,即文本只剩下。 但bottomAnimation的代碼執行但不顯示。 –

+0

那麼你已經添加了moveAnimation到btnSpecialForListing.titleLabel.layer那麼你到底想要做什麼?我真的不知道它 – Pancho

+0

看到,我有標籤上我要添加從底部開始動畫(底部動畫從-7到-13位置),動畫1完成,然後完成底部動畫,或者你可以說當底部動畫停止我們的第二個動畫(moveAnimation)開始並且向左移動,但在完成moveAnimation後,我的文本返回到它的原始位置,並再次開始相同的循環。 –

相關問題