2
請不要參考CABasicAnimation returns to the original position before the next animation和Objective-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"];
}
}
任何幫助將不勝感激。 謝謝!
是的,我做了。 但是在第一個循環完成之後,只有移動動畫才起作用,即文本只剩下。 但bottomAnimation的代碼執行但不顯示。 –
那麼你已經添加了moveAnimation到btnSpecialForListing.titleLabel.layer那麼你到底想要做什麼?我真的不知道它 – Pancho
看到,我有標籤上我要添加從底部開始動畫(底部動畫從-7到-13位置),動畫1完成,然後完成底部動畫,或者你可以說當底部動畫停止我們的第二個動畫(moveAnimation)開始並且向左移動,但在完成moveAnimation後,我的文本返回到它的原始位置,並再次開始相同的循環。 –