【问题标题】:CAKeyframeAnimation with Path build with CGPathAddArcToPoint doesn't work使用 CGPathAddArcToPoint 构建路径的 CAKeyframeAnimation 不起作用
【发布时间】:2023-03-29 19:28:01
【问题描述】:

我有一个 keyframeAnimation 并定义了一个路径,但动画不起作用。

你看出什么不对了吗? :S

代码如下:

CAKeyframeAnimation *animKF = [CAKeyframeAnimation animationWithKeyPath:@"position"];

CGMutablePathRef animationPath = CGPathCreateMutable();

CGPathMoveToPoint(animationPath, NULL, 300, 100);

CGPathAddArcToPoint(animationPath, NULL, 300, 100, 800, 500, 500);

animKF.path = animationPath;

animKF.duration = 3;

animKF.rotationMode =  kCAAnimationRotateAuto;

[imageView.layer addAnimation:animKF forKey:@"keyframe"];

非常感谢

【问题讨论】:

  • “不起作用”是什么意思?怎么了?什么都没有还是错了?
  • 另外,一旦你将它分配给动画,不要忘记使用CGPathRelease(animationPath);释放animationPath。

标签: ios core-animation calayer caanimation cakeyframeanimation


【解决方案1】:

您可能认为CGPathMoveToPoint() 是真正“移动”要点的方法,抱歉并非如此。我猜您的意图是为“路径”属性设置动画。因此,您应该创建几个(在您的情况下为 3 个)CGMutablePathRef 对象作为keyframe。然后调用

[animKF setValues: @[path1,path2,path3]];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    相关资源
    最近更新 更多