【问题标题】:CAShapeLayer strokeStart and strokeEnd positionsCAShapeLayer strokeStart 和 strokeEnd 位置
【发布时间】:2023-05-24 16:41:02
【问题描述】:

我有这段代码:

    let arcPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, frame.width, frame.height))

    circleLayer = CAShapeLayer()
    circleLayer.path = arcPath.CGPath
    circleLayer.fillColor = UIColor.clearColor().CGColor
    circleLayer.strokeColor = UIColor.blueColor().CGColor
    circleLayer.lineWidth = 5.0;

    circleLayer.strokeStart = 0
    circleLayer.strokeEnd = 0.7

结果如下:

如您所见,圆弧从圆的右侧开始。我想从顶部开始绘制弧线。我该怎么做?我是否必须将整个物体旋转 -90 度才能完成我想要做的事情?

谢谢。

【问题讨论】:

    标签: ios swift cashapelayer


    【解决方案1】:

    你可以这样创建路径

    let bezierPath = UIBezierPath(arcCenter:CGPointMake(100,100), radius:40, startAngle: CGFloat(M_PI_2) * 3.0, endAngle:CGFloat(M_PI_2) * 3.0 + CGFloat(M_PI) * 2.0, clockwise: true)
    

    截图

    【讨论】:

    • 因此,我如何从用户点击的任意位置开始?假设他们在 Apple 的 100 度圆上敲击,我想顺时针一直画到 Apple 的 45 度?
    【解决方案2】:

    我认为从您原来的startAngleendAngle 中减去90 * M_PI / 180 就足以完成这项任务。

    天知道为什么苹果决定把 90 度当成*。

    【讨论】: