有没有一种方法可以动态调整贝塞尔曲线四边形的控制点?

我正在为孩子们创建一个小的拖放绘图应用程序。我希望他们在画布上添加一条线,然后调整曲线点以用手指拖动产生微笑或皱眉。

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

这是我创建路径的方式:

  //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)


任何帮助/提示将不胜感激

最佳答案

我无法达到想要调整现有路径的四曲线的目的。相反,我不得不每次都使用调整后的曲线重新绘制路径。

关于ios - 快速更新addQuadCurve控制点?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50704663/

10-10 20:34