首页 > 解决方案 > Swift 二次曲线路径不以曲线闭合

问题描述

我有一个 CGPoints 数组,我正在根据这个数组绘制一组曲线。我看到的是“形状”没有关闭。

let counterPath = UIBezierPath()
counterPath.move(to: counterPoints![0])

for (index, _) in counterPoints!.enumerated() {
    if index % 2 == 0 {
        if (index + 2) < counterPoints!.count {
            counterPath.addQuadCurve(to: counterPoints![index + 2], controlPoint: counterPoints![index + 1])
        } else {
            //This should close the shape
            counterPath.addQuadCurve(to: counterPoints![0], controlPoint: counterPoints![counterPoints!.count - 1])
        }
    }
}

counterPath.close()

每个点都在一个圆的圆周上。偶数点略“高”(它们位于圆周上方),所有奇数点略“低”(略低于圆周)。

发生的事情是最后一条曲线没有被绘制出来。我知道通常你只是调用 path.close() 但我需要它以四边形曲线关闭。

整体形状看起来像一朵由内而外的花朵。

它的外观示例:

形状图片

这是 CGPoints 的数组:

[(288.079231262207, 109.933921813965), (244.400169372559, 102.082759857178), (227.010290145874, 61.2527008056641), (193.637225151062, 90.5069541931152), (150.87366104126, 78.6449432373047), (152.937526702881, 122.97599029541), (117.0, 149.01433874201), (152.945823669434, 175.041234970093), (150.89608001709, 219.372932434082), (193.656756401062, 207.497505187988), (227.038249969482, 236.740921020508), (244.415832519531, 195.904750823975), (288.091667175293, 188.040241241455), (267.0, 148.99356841296), (207.0, 149.0), (267.0, 148.999997138029)]

标签: iosswiftuibezierpath

解决方案


推荐阅读