addArc(withCenter) 闭合路径

joe*_*oey 2 ios uibezierpath swift3

以下代码:

  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)
Run Code Online (Sandbox Code Playgroud)

产生这个:

在此处输入图片说明

好吧,我错过了什么吗?我不想关闭这条路。我从不打电话path1.close()。我想从弧的末端添加另一条直线,而不是从它的封闭版本。基本上,我不想关闭半圆,我该怎么做?

Leo*_*bus 7

您需要以 -90 度开始弧并以 +90 度结束。你还需要改变它的方向。您需要执行以下操作:

path1.addArc(withCenter: CGPoint(x: 180, y: 20), radius: 15, startAngle: -.pi/2, endAngle: .pi/2, clockwise: true)
Run Code Online (Sandbox Code Playgroud)

如果你想完成形状,它看起来像这样:

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)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明