0

I need to move object (UIImageView) from point A to point B, then rotate image at point B by 180 degrees to face the opposite direction and move object from B to A (backwards).

I have the code below which moves from A to B. I also know how to rotate UIImageView. But how to know when object has reached point B and how to apply rotation action considering there are many objects on the screen?

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation    animationWithKeyPath:@"position"];
pathAnimation.duration = speed;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO; 
CGMutablePathRef pointPath = CGPathCreateMutable();
CGPathMoveToPoint(pointPath, NULL, rect.origin.x, rect.origin.y);
CGPathAddLineToPoint(pointPath, NULL, x, y);
pathAnimation.path = pointPath;
CGPathRelease(pointPath);   
[imageView.layer addAnimation:pathAnimation forKey:[NSString    stringWithFormat:@"pathAnimation%@",objId]];
[imageView release];
Vad
  • 3,658
  • 8
  • 46
  • 81

2 Answers2

1

You can use the CAAnimation delegate method

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
Nyx0uf
  • 4,609
  • 1
  • 25
  • 26
1

Set a delegate on the CAAnimation object, and in the delegate implement the animationDidStop:finished: method.

OTOH, the animation you described sounds like it could be done easily enough with UIView's animation support. See Animating Views with Blocks if you're targeting 4.0 and up, or Animating Views if you're still targeting earlier versions.

Anomie
  • 92,546
  • 13
  • 126
  • 145
  • I actually have a complex path to move through. For simplicity I use A and B. YOu mention CGAnimation but I do not have that object initialized. I will research how to do it. Thanks – Vad Aug 31 '11 at 15:20
  • @Vad: I meant CAAnimation, which is a superclass of CAKeyframeAnimation. Apple has too many different little prefixes for their classes. – Anomie Aug 31 '11 at 15:29