gpt4 book ai didi

ios - 快速更新 addQuadCurve 控制点?

转载 作者:行者123 更新时间:2023-11-30 11:26:21 37 4
gpt4 key购买 nike

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

我正在为 children 创建一个小型拖放绘图应用程序。我希望他们在 Canvas 上添加一条线,然后通过拖动手指来调整曲线点以创建微笑或皱眉。

我目前正在使用 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

}

将其添加到 View

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/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com