I am animating my UIImageView using CAAnimation using the layer property, for example:
[imageView.layer addAnimation:pathAnimation forKey:[NSString stringWithFormat:@"pathAnimation%@",objId]];
But at the end of my animation (after the object has moved from the starting point), when I read the coordinates of the XY frame or the coordinates of the center, they always seem original, and not the ones the object moved to.
How to read the coordinates of a layer to determine the correct location of my moving object?
Here is my code:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)]; imageView.image = [UIImage imageNamed:@"banner1.jpg"]; imageView.animationDuration = 2; imageView.animationRepeatCount = 0; imageView.tag = 100000; imageView.layer.frame = imageView.frame; [self.view addSubview:imageView]; CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.duration = 2.0f; pathAnimation.delegate=self; pathAnimation.calculationMode = kCAAnimationPaced; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; CGMutablePathRef pointPath = CGPathCreateMutable(); CGPathMoveToPoint(pointPath, NULL, 100, 100); CGPathAddLineToPoint(pointPath, NULL, 300, 200); CGPathAddLineToPoint(pointPath, NULL, 200, 150); pathAnimation.path = pointPath; CGPathRelease(pointPath); [imageView.layer addAnimation:pathAnimation forKey:@"pathAnimation"]; [imageView release];
source share