views:

211

answers:

1

Hello experts! I am trying to perform some kind of animation of a layer in my iPhone application. It does not matter what I do I always get the same results: after the animation is done it jerks back into it's original position. Even though I set removedOnCompletion to false there is no difference.

What am I missing here?

Thanks in advance!

EDIT: Really need help with this one guys. I am creating animations with CAKeyframeAnimation and CABasicAnimation objects, then adding them to a CAAnimationGroup which I in turn att to the layer. The animation works as predicted except that it always snaps back to it's original state. This is the case even though I set removedOnCompletion = NO; on all animation-objects and the animation group.

Some one please point me in the right direction! I you live in the Stockholm area I will buy you a coffe. =) New code posted below:

CABasicAnimation *leveloutLeafAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
leveloutLeafAnimation.removedOnCompletion = NO;
leveloutLeafAnimation.duration = 1.0; 
leveloutLeafAnimation.repeatDuration = 20; 
CATransform3D transformLeafToRotation = CATransform3DMakeRotation(0.0, 0.0, 0.0, 1);
CATransform3D transformLeafFromRotation = CATransform3DMakeRotation([self _degreesToRadians:270.0], 0.0, 0.0, 1);
leveloutLeafAnimation.fromValue = [NSValue valueWithCATransform3D:transformLeafFromRotation];
leveloutLeafAnimation.toValue = [NSValue valueWithCATransform3D:transformLeafToRotation];

//Create an animation group to combine the animations.
CAAnimationGroup *theAnimationGroup = [CAAnimationGroup animation];

//The animationgroup conf.
theAnimationGroup.delegate = self;
theAnimationGroup.duration = animationDuration;
theAnimationGroup.removedOnCompletion = NO;
theAnimationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
theAnimationGroup.animations = [NSArray arrayWithObjects:leveloutLeafAnimation, leafMoveAnimation, nil];

// Add the animation group to the leaf layer.
[leafViewLayer addAnimation:theAnimationGroup forKey:@"animatLeafFalling"];
+2  A: 

Not sure if this is helpful, but this guy seems like he was having a similar problem.

You might have to set the transform property of the layer while the animation is running to transformLeafToRotation.

Good luck!

Frank Schmitt
Thanks a lot Frank Schmitt! You are the man.theAnimationGroup.fillMode = kCAFillModeForwards; Was the key.If you come by Stockholm I owe you a coffe. =)
ABeanSits