11
我试图做一个动画,我将一个CGPoint从一个视图移动到另一个视图,我想找到点的坐标将参考首先,我可以做动画。将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;
任何想法?
这两个视图都可以显示吗?它们是否包含在更大的视图中? –