Question

I'm trying to scale an image down, change the image, then scale it back up.

CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = [NSNumber numberWithDouble:0];
shrink.duration = 1;
    shrink.delegate = self;
    [myImageView.layer addAnimation:shrink forKey:@"shrink"];   

makes the shrink, then when it completes, I change the image, and start the grow:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag 
{
    myImageView.image = [images objectAtIndex:image];
CABasicAnimation* grow = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
grow.toValue = CGAffineTransformMakeScale(1,1);
    grow.delegate = self;
grow.duration = 1;
[myImageView.layer addAnimation:grow forKey:@"grow"];   
}

This works great on the simulator, but on the device, when the shrink completes, I get a flash of the full-size, old image, then the grow animation begins with the new image.

Any idea how to get rid of that flash?

(I've tried "removedOnCompletion = NO;" and attempted setting the affineTransform equal to the scaled down size after the first completion, but didn't have much luck.)

Any tips appreciated.

kb

Edit:

Excellent! Setting the following:

shrink.fillMode = kCAFillModeForwards; 
shrink.removedOnCompletion = NO; 

Removed the flashing. Thanks, Ben!

Was it helpful?

Solution

Try setting your animation's fillMode to kCAFillModeForwards. That should leave the item as it was at the end of the animation, rather than before.

OTHER TIPS

I've had the same problem when I tried to create another CAAnimation in the animationDidStop method. I suggest using CAKeyframeAnimation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top