【问题标题】:addArc(withCenter) closing pathaddArc(withCenter) 关闭路径
【发布时间】:2016-11-23 05:08:18
【问题描述】:

以下代码:

  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()。我想从弧的末端添加另一条直线,而不是从它的封闭版本。基本上,我不希望半圈被封闭,我该怎么做?

【问题讨论】:

    标签: ios swift3 uibezierpath


    【解决方案1】:

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

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

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

    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)
    

    【讨论】:

      【解决方案2】:

      希望这将帮助您实现您的结果

       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
      

      上面的代码将在你的画布中绘制它。

      【讨论】:

        猜你喜欢
        • 2016-05-26
        • 2011-09-16
        • 1970-01-01
        • 2014-08-02
        • 1970-01-01
        • 2011-12-01
        • 2011-05-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多