addArc(withCenter) closing path

隐身守侯 提交于 2019-11-28 02:27:44

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)

Hope this will help you to achieve your result

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

        let path = UIBezierPath()
        path.move(to: CGPoint(x: 10, y: 100))
        path.addLine(to: CGPoint(x: 180, y: 100))
        path.addArc(withCenter: CGPoint(x:180 , y: 85), radius: 15, startAngle: (3.14159 / 2), endAngle:  (3 * 3.14159 / 2), clockwise: false)

    path.addLine(to: CGPoint(x: 10, y: 70)) //y = radius * 2

Above code will draw this in your canvas .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!