我如何抛物线翻译?

bpa*_*apa 6 iphone animation linear-algebra uiview affinetransform

我正在开发一款带有一些简单动画的iPhone应用程序.

我有一个想要翻译的观点,但不是一条线.我想抛物面翻译它.想象一下,我正在制作一辆沿弯曲道路行驶的汽车.

我知道我可以将转换正确地设置为CGAffineTransform的实例

问题是,我不知道如何创建转换.我知道如何缩放,翻译等,但我如何翻译?它甚至可能吗?

Bra*_*son 25

要沿平滑曲线制作动画,您需要使用CAKeyframeAnimation.在这个答案中,我提供了一个组合动画的代码,它可以沿曲线移动图像视图,同时调整大小并淡化它.该代码的相关部分如下:

// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;

CGPoint endPoint = CGPointMake(480.0f - 30.0f, 40.0f);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, viewOrigin.y, endPoint.x, viewOrigin.y, endPoint.x, endPoint.y);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
Run Code Online (Sandbox Code Playgroud)

这将创建一个带有两个控制点的曲线,一个位于视图原点,另一个位于显示屏的右上角(在横向模式下).有关构造路径的更多信息,请参阅" Quartz 2D编程指南"或" 动画类型和时序编程指南".

要使用此动画,您需要使用以下内容将其添加到视图的图层:

[imageViewForAnimation.layer addAnimation:pathAnimation forKey:@"curveAnimation"];
Run Code Online (Sandbox Code Playgroud)