快速自定义UIBezierPath(Arc麻烦)

时间:2018-07-10 20:43:25

标签: ios swift uibezierpath

我写这段代码:

let leftUpPath = UIBezierPath()
leftUpPath.move(to: CGPoint(x: 40, y: 40))
leftUpPath.addArc(withCenter: CGPoint(x: 40, y: 40),
    radius: 10,
    startAngle: CGFloat(Double.pi),
    endAngle: CGFloat(3*Double.pi),
    clockwise: true)
leftUpPath.addLine(to: CGPoint(x: 30, y: 50))
leftUpPath.addLine(to: CGPoint(x: 90, y: 50))
leftUpPath.addLine(to: CGPoint(x: 80, y: 30))
leftUpPath.addLine(to: CGPoint(x: 40, y: 30))

这会在我的故事板中显示给我:

Story Board

但是我想要这个:

what I want

如果有人有解决方案,我想我的麻烦就是在哪里画弧线...感谢您的帮助

1 个答案:

答案 0 :(得分:1)

第一个点和弧线不正确。您需要:

let leftUpPath = UIBezierPath()
leftUpPath.move(to: CGPoint(x: 40, y: 30))
leftUpPath.addArc(withCenter: CGPoint(x: 40, y: 40),
                  radius: 10,
                  startAngle: .pi * 3 / 2,
                  endAngle: .pi,
                  clockwise: false)
leftUpPath.addLine(to: CGPoint(x: 30, y: 50))
leftUpPath.addLine(to: CGPoint(x: 90, y: 50))
leftUpPath.addLine(to: CGPoint(x: 80, y: 30))
leftUpPath.addLine(to: CGPoint(x: 40, y: 30))