gpt4 book ai didi

ios - 从一点到另一点的弯曲箭头

转载 作者:行者123 更新时间:2023-11-29 05:57:13 27 4
gpt4 key购买 nike

我需要绘制一个从一点到另一点的弯曲箭头。我确实设法从下面的扩展中得到了一个直箭头。

extension UIBezierPath {

static func arrow(from start: CGPoint, to end: CGPoint, tailWidth: CGFloat, headWidth: CGFloat, headLength: CGFloat) -> UIBezierPath {
let length = hypot(end.x - start.x, end.y - start.y)
let tailLength = length - headLength

func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { return CGPoint(x: x, y: y) }
let points: [CGPoint] = [
p(0, tailWidth / 2),
p(tailLength, tailWidth / 2),
p(tailLength, headWidth / 2),
p(length, 0),
p(tailLength, -headWidth / 2),
p(tailLength, -tailWidth / 2),
p(0, -tailWidth / 2)
]

let cosine = (end.x - start.x) / length
let sine = (end.y - start.y) / length
let transform = CGAffineTransform(a: cosine, b: sine, c: -sine, d: cosine, tx: start.x, ty: start.y)

let path = CGMutablePath()
path.addLines(between: points, transform: transform)


path.closeSubpath()

return self.init(cgPath: path)
}}

我目前从上面的代码中得到了什么。 What I have now

我需要什么。

What I need

最佳答案

使用addArc方法创建曲线(而不是直线):-

path.addArc(tangent1End: start, tangent2End: end, radius: 30)

path.addArc(center: CGPoint(x: 100, y: 100), radius: 30, startAngle: 270, endAngle: 360, clockwise: true, transform: transform)

关于ios - 从一点到另一点的弯曲箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55038312/

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