I have used this code to animate the circle along a fixed custom route path along two buttons using their x & y coordinates.
Now I want to know the exact location of circle at each route while it is rotating or animating how could I know this?
- (void) animateCicleAlongPath:(NSInteger)pt1:(NSInteger)pt2
{
UIButton *animatebtn1 = (UIButton *)[self.view viewWithTag:pt1];
UIButton *animatebtn2 = (UIButton *)[self.view viewWithTag:pt2];
NSLog(@"%@",animatebtn1);
NSLog(@"%@",animatebtn2);
NSLog(@"%@",NSStringFromCGRect(circleView.frame));
int a1;
int a2;
int b1;
int b2;
a1=animatebtn1.frame.origin.x;
a2=animatebtn1.frame.origin.y;
b1=animatebtn2.frame.origin.x;
b2=animatebtn2.frame.origin.y;
pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[UIView setAnimationDidStopSelector:@selector(animationDidStart:)];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = YES;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, b1, b2);
NSLog(@"%@",[finalpath description]);
for (int i=0; i<finalpath.count; i++) {
int j=[[finalpath objectAtIndex:i]intValue];
UIButton *animatebtn = (UIButton *)[self.view viewWithTag:j];
int p1=animatebtn.frame.origin.x;
int p2=animatebtn.frame.origin.y;
CGPathAddLineToPoint(curvedPath, NULL, p1,p2);
}
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
UIGraphicsBeginImageContext(CGSizeMake(20,20));
// CGContextRef ctx = UIGraphicsGetCurrentContext();
//Set context variables
CGContextSetLineWidth(context, 1.5);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
//Draw a circle - and paint it with a different outline (white) and fill color (green)
CGContextAddEllipseInRect(context, CGRectMake(1, 1, 18, 18));
CGContextDrawPath(context, kCGPathFillStroke);
UIImage *circle = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
circleView = [[UIImageView alloc] initWithImage:circle];
[imageScrollView addSubview:circleView];
[imageScrollView bringSubviewToFront:circleView];
[circleView setHidden:NO];
circleView.alpha=1;
pathAnimation.speed=0.5;
pathAnimation.duration=10;
circleView.animationDuration=10;
[circleView.layer addAnimation:pathAnimation forKey:@"moveTheSquare"];
[circleView release];
}
CALayer provides a method, -presentationLayer, which returns a layer with the current animation state applied. So long as you have the layer being animated, you can inspect the current position of animation through the presentation layer.