addArc(withCenter) closing path

前端 未结 2 765
既然无缘
既然无缘 2020-12-07 00:28

The following code:

  let size = CGSize(width: 200, height: 30)
  let rect = CGRect(origin: .zero, size: size)

  let path1 = UIBezierPath()
  path1.move(to:         


        
2条回答
  •  春和景丽
    2020-12-07 00:57

    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)
    

提交回复
热议问题