CABasicAnimation vuelve a su posición original después de terminar su ciclo 1
Frecuentes
Visto 2,827 equipos
2
Don't refer CABasicAnimation vuelve a la posición original antes de la siguiente animación e Objective-C - CABasicAnimation aplicando cambios después de la animación? e CABasicAnimation rotar vuelve a la posición original i have tried.
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"];
}
}
Any help would be greatly appreciated. Thanks !!
2 Respuestas
7
¿Has probado esto?
moveAnimation.fillMode = kCAFillModeForwards;
moveAnimation.removedOnCompletion = NO;
EDITAR
As far as I can see you can also use animateWithDuration
which has a completion block.
Example would be:
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;
}];
}];
contestado el 22 de mayo de 14 a las 14:05
2
Rápido 4.2/5:
moveAnimation.fillMode = .forwards
moveAnimation.isRemovedOnCompletion = false
respondido 02 mar '20, 14:03
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas ios objective-c animation cabasicanimation or haz tu propia pregunta.
Yes,i did. but after completion of 1st cycle only moveAnimation works i.e text only goes left. but the code for bottomAnimation executes but doesn't display. - enfermedad venérea
Well you have added moveAnimation to btnSpecialForListing.titleLabel.layer so what exactly you're trying to do? I don't really get it - Pancho
see,i have label on which i want to add animation which starts from bottom(bottomAnimation from -7 to -13 position),animation 1 complete then on completion of bottom animation or you can say when bottomAnimation stop our 2nd animation(moveAnimation) starts and goes left.but after completion of moveAnimation my text back to it's original position.and starts once again the same cycle. - enfermedad venérea
you can try taking label with frame 0,450,320,30.and copy the above code.you will get an idea. - enfermedad venérea
Thanks...but i got the error read-only variable isn't assignable in rect.origin.y = -7 line and no known class method error by using animateWithDuration method. I am using xcode 5.0 - enfermedad venérea