我正在尝试制作一个动画,将一个 CGPoint 从一个视图移动到另一个视图,我想找到该点相对于第一个视图的坐标,以便我可以制作动画。
因此,假设我在 view2 中有一个点 (24,15),并且我想将其动画化到 view1,我仍然想在新视图中保留该点的值,因为我将该点添加为新视图,但对于动画,我需要知道该点所在位置的值,以便我可以进行补间。
请参考这张图:
现在这就是我想要做的:
customObject *lastAction = [undoStack pop];
customDotView *aDot = lastAction.dot;
CGPoint oldPoint = aDot.center;
CGPoint newPoint = lastAction.point;
newPoint = [lastAction.view convertPoint:newPoint toView:aDot.superview];
CABasicAnimation *anim4 = [CABasicAnimation animationWithKeyPath:@"position"];
anim4.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim4.fromValue = [NSValue valueWithCGPoint:CGPointMake(oldPoint.x, oldPoint.y )];
anim4.toValue = [NSValue valueWithCGPoint:CGPointMake( newPoint.x, newPoint.y )];
anim4.repeatCount = 0;
anim4.duration = 0.1;
[aDot.layer addAnimation:anim4 forKey:@"position"];
[aDot removeFromSuperview];
[lastAction.view addSubview:aDot];
[lastAction.view bringSubviewToFront:aDot];
aDot.center = newPoint;
有任何想法吗?