iOS - 将 UIBezierpath 的 lineJoinStyle 设置为 .round 不起作用 (SWIFT)

iOS - Setting lineJoinStyle to .round for UIBezierpath does not work (SWIFT)

我的代码是这样的:

let myPath = UIBezierPath()
myPath.lineJoinStyle = .round
let rect = bounds
myPath.move(to: CGPoint(x: rect.maxX * 0.05, y: rect.midY))
myPath.addCurve(to: CGPoint(x: rect.maxX / 3, y: rect.maxY / 10),
                controlPoint1: CGPoint(x: rect.midX/5, y: rect.midY/2),
                controlPoint2: CGPoint(x: rect.midX/3, y: rect.midY/3))
myPath.addQuadCurve(to: CGPoint(x: rect.maxX * 2/3, y: rect.maxY / 5),
                    controlPoint: CGPoint(x: rect.maxX * 0.6, y: rect.maxY / 4))

但是第一条和第二条曲线的连接点还是不圆。应该怎么做才能圆润光滑?

这是结果图片:

这里按照您的期望https://prnt.sc/sgmyp6我已经使用addQuadCurve函数制作了一条曲线。

拿了 UIViewHeight = 200Width = 300

@IBOutlet weak var centerView: UIView!

 override func viewDidLoad() {
        super.viewDidLoad()
        let centerViewW = centerView.frame.size.width. //Width Of your view
        let centerViewH = centerView.frame.size.height //Height Of your view

        let myPath: UIBezierPath = UIBezierPath()
        let drawingLayer = CAShapeLayer()
        drawingLayer.strokeColor =  UIColor.red.cgColor
        drawingLayer.fillColor = UIColor.clear.cgColor
        drawingLayer.lineWidth = 4.0

        //This is starting point from where you start drawing
        myPath.move(to: CGPoint(x: 0, y: centerViewH-25))

        //This is First Curve
        myPath.addQuadCurve(to: CGPoint(x: ((centerViewW/2)+10), y: (centerViewH/3+15)), controlPoint: CGPoint(x: 40, y: 20))

        drawingLayer.path = myPath.cgPath
        centerView.layer.addSublayer(drawingLayer)

        //This is Second Curve
        myPath.addQuadCurve(to: CGPoint(x: centerViewW, y: (centerViewH/2)), controlPoint: CGPoint(x: (centerViewW - 45), y: (centerViewH/2)+40))

        drawingLayer.path = myPath.cgPath
        centerView.layer.addSublayer(drawingLayer)
}

您只需 update/change 控制点与直线的斜率相匹配。

输出:-