Swift 更新 addQuadCurve 控制点?

Swift Update addQuadCurve Control Point?

有没有办法动态调整贝塞尔曲线的四曲线控制点?

我正在为孩子们开发一个小型 drag/drop 绘图应用程序。我希望他们在 canvas 上添加一条线,然后使用手指拖动调整曲线点以创建微笑或皱眉。

我目前正在使用 UIBezierPath 绘制一条简单的线,并且我已经向 parent 添加了一个手势识别器。我试过删除所有点并在拖动时添加新的四边形曲线以及使用新的控制点坐标重新绘制路径。

这是我创建路径的方式:

  //path defined else where
     func createBezierPath (withRectRef rectRef: RectFramer)-> UIBezierPath {


        path.move(to: rectRef.bottomLeft)
        path.move(to: rectRef.bottomRight)
        path.move(to: rectRef.topRight)
        path.addQuadCurve(to: rectRef.topLeft, controlPoint: CGPoint(x:rectRef.midX, y: rectRef.midY )) // top middle control point

        return path

    }

将其添加到视图

let shapeLayer = CAShapeLayer()
shapeLayer.path = createBezierPath(withRectRef: frameRef!).cgPath

        shapeLayer.strokeColor = UIColor.blue.cgColor
        shapeLayer.fillColor = UIColor.clear.cgColor
        shapeLayer.lineWidth = 4.0
        shapeLayer.position = CGPoint(x: 0, y: 0)
        self.backgroundColor = UIColor.clear

        // add the new layer to our custom view
        self.layer.addSublayer(shapeLayer)

        let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
        gestureRecognizer.delegate = self
        self.addGestureRecognizer(gestureRecognizer)

任何 help/tips 将不胜感激

尝试调整现有路径的四边形曲线时,我无法实现我想要的效果。相反,我每次都必须使用调整后的曲线重新绘制路径。