addArc(withCenter) 闭合路径 [英] addArc(withCenter) closing path
本文介绍了addArc(withCenter) 闭合路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码:
let size = CGSize(width: 200, height: 30)
let rect = CGRect(origin: .zero, size: size)
let path1 = UIBezierPath()
path1.move(to: CGPoint(x: 10, y: 5))
path1.addLine(to: CGPoint(x: 180, y: 5))
path1.addArc(withCenter: CGPoint(x: 180, y: 20), radius: 15,
startAngle: (3.14159 / 2), endAngle: (3 * 3.14159 / 2), clockwise: false)
产生这个:
好的,我是不是遗漏了什么?我不想关闭这条路.我从不调用 path1.close()
.我想从弧的末端添加另一条直线,而不是从它的封闭版本.基本上,我不想关闭半圆,我该怎么做?
Ok, am I missing something? I do not want to close this path. I never call path1.close()
. I want to add another straight line from the end of the arc, not from the closed version of it. Basically, I don't want the half circle to be closed, how can I do that?
推荐答案
您需要在 -90 度处开始圆弧并在 +90 度处结束圆弧.你还需要改变它的方向.您需要执行以下操作:
You need to start your arc at -90 degrees and end it at +90 degrees. You need also to change its direction. You need to do as follow:
path1.addArc(withCenter: CGPoint(x: 180, y: 20), radius: 15, startAngle: -.pi/2, endAngle: .pi/2, clockwise: true)
如果你想完成形状,它看起来像这样:
If you would like to complete the shape it would look like this:
let path1 = UIBezierPath()
path1.move(to: CGPoint(x: 10, y: 5))
path1.addLine(to: CGPoint(x: 180, y: 5))
path1.addArc(withCenter: CGPoint(x: 180, y: 20), radius: 15, startAngle: -.pi/2, endAngle: .pi/2, clockwise: true)
path1.addLine(to: CGPoint(x: 10, y: 35))
path1.addArc(withCenter: CGPoint(x: 10, y: 20), radius: 15, startAngle: .pi/2, endAngle:-.pi/2 , clockwise: true)
这篇关于addArc(withCenter) 闭合路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文