Note that there are some explanatory texts on larger screens.

plurals
  1. POCALayer Positioning After Object Has Moved
    text
    copied!<p>I animate my UIImageView with CAAnimation using layer property like so:</p> <pre><code> [imageView.layer addAnimation:pathAnimation forKey:[NSString stringWithFormat:@"pathAnimation%@",objId]]; </code></pre> <p>But at the end of my animation (after object has moved from original point) when I read the frame's X Y coordinates or center coordinates they always appear to be original ones, not those where the object has moved to.</p> <p>How to read layer's coordinates so I determine the correct location of my moving object?</p> <p>Here is my code:</p> <pre><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]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload