1

How can I hide my UIImageView after the animation is completed? My animation is working fine when I segue into the view. I want to be a able to hide the image after the animation is complete. How might I do that?

-(void) animate
{
    NSLog(@"Animate");

    CGPoint startPoint = [pickerCircle center];
    CGPoint endPoint = [pickerButton1 center];

    CGMutablePathRef thePath = CGPathCreateMutable();
    CGPathMoveToPoint(thePath, NULL, startPoint.x, startPoint.y);
    CGPathAddLineToPoint(thePath, NULL, endPoint.x, endPoint.y);

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.duration = 3.f;
    animation.path = thePath;
    animation.repeatCount = 2;
    animation.removedOnCompletion = YES;
    [pickerCircle.layer addAnimation:animation forKey:@"position"];
    pickerCircle.layer.position = endPoint;
}
Jack Shultz
  • 2,031
  • 2
  • 30
  • 53

2 Answers2

1

Set the animation's delegate property to self like so:

animation.delegate = self;

And then you can use:

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    // hide your UIImage here
}

It will be called when the animation is done.

Clay Garrett
  • 1,023
  • 8
  • 11
-1

Did you try completion? Here example 4.2there is an example about showing and hiding an view with using completion. I don't know animations well but I think completion should work.

Gürhan KODALAK
  • 570
  • 7
  • 20
  • Sorry, this does not really answer my question. Yes I see examples in other types of animations that use `completion`: blocks, I am looking specifically for help with the `CAKeyframeAnimation` – Jack Shultz Apr 04 '15 at 23:01