gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:01:50 25 4
gpt4 key购买 nike

我的代码是这样的:

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

但仍然第一和第二曲线连接点不圆。我该怎么做才能使它圆润光滑?

这是结果图像:

Result Image

最佳答案

这里按您的期望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)
}

您只需要更新/更改控制点以匹配线的斜率。

输出:-

enter image description here

关于swift - iOS - 为 UIBezierpath 将 lineJoinStyle 设置为 .round 不起作用(SWIFT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61777665/

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