tags:

views:

183

answers:

1

Hello all,

I am using the following code to move a label from one position to another in x direction

CABasicAnimation *theAnimation; 
    theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    theAnimation.duration=1;
    theAnimation.repeatCount=1;
    theAnimation.autoreverses=NO;
    theAnimation.fromValue=[NSNumber numberWithFloat:0];
    theAnimation.toValue=[NSNumber numberWithFloat:80];


    [lbl.layer addAnimation:theAnimation forKey:@"animateLayer"];

But in this case at the end of the animation the label shifts back to its original position. How to make sure it stays at the position where it is moved.

Is there any good way to do it without using timer and changing the coordinates on our own.

+2  A: 

After the animation completes, it is removed. That's why it snaps back. Add this to your animation:

theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;

This will prevent the animation from being removed, and tells the animation to remain in its final state upon completion.

Alex
amazing it works fine.
rkb