【问题标题】:Animate a point of a Bezier curve [duplicate]为贝塞尔曲线的一个点设置动画[重复]
【发布时间】:2013-09-13 19:05:32
【问题描述】:

是否可以为贝塞尔曲线的点设置动画?我正在尝试从直线平滑过渡到箭头。

这是代码中该行的样子

//// Color Declarations
UIColor* white = [UIColor colorWithRed: 1 green: 1 blue: 1 alpha: 0.374];

//// Group
{
    //// Bezier Drawing
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint: CGPointMake(30.5, 43.5)];
    [bezierPath addLineToPoint: CGPointMake(30.5, 29.59)];
    [bezierPath addLineToPoint: CGPointMake(30.5, 15.5)];
    bezierPath.lineCapStyle = kCGLineCapRound;

    bezierPath.lineJoinStyle = kCGLineJoinBevel;

    [white setStroke];
    bezierPath.lineWidth = 5.5;
    [bezierPath stroke];
}

...但是我不知道如何选择一个点并为其设置动画。这甚至可能吗?

【问题讨论】:

    标签: ios objective-c animation caanimation


    【解决方案1】:

    使用CAShapeLayer 的显式CGPath 动画:

    // Create the starting path. Your curved line.
    UIBezierPath * startPath; 
    // Create the end path. Your straight line.
    UIBezierPath * endPath; 
    
    // Create the shape layer to display and animate the line.
    CAShapeLayer * myLineShapeLayer = [[CAShapeLayer alloc] init];
    
    CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
    pathAnimation.fromValue = (__bridge id)[startPath CGPath];
    pathAnimation.toValue = (__bridge id)[endPath CGPath];
    pathAnimation.duration = 5.0f;
    [myLineShapeLayer addAnimation:pathAnimation forKey:@"animationKey"];
    

    【讨论】:

      【解决方案2】:

      不清楚你在问什么。您是否尝试通过移动控制点之一来更改线条形状的动画?

      动画路径更改的方法是创建一个 CAShapeLayer 并将其安装为视图层的子层。然后,如果您更改与形状图层关联的路径,系统将使用隐式动画进行更改。

      请注意,形状层中的路径需要具有相同数量/类型的控制点,否则动画的结果是“未定义的”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多