我使用图层属性使用 CAAnimation 为我的 UIImageView 设置动画,如下所示:
[imageView.layer addAnimation:pathAnimation forKey:[NSString stringWithFormat:@"pathAnimation%@",objId]];
但是在我的动画结束时(在对象从原始点移动之后),当我读取框架的 XY 坐标或中心坐标时,它们总是看起来是原始坐标,而不是对象移动到的那些坐标。
如何读取图层的坐标以便确定移动对象的正确位置?
这是我的代码:
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];