【问题标题】:UIBezierPath's close() function doesn't work for SKShapeNodeUIBezierPath 的 close() 函数不适用于 SKShapeNode
【发布时间】:2019-08-01 05:59:12
【问题描述】:

close() 函数应该在子路径的第一个点和最后一个点之间创建一条线段。它在操场上工作,但不工作 当我使用 UIBezierPath 创建 SKShapeNode 并将其用于 ARSKView 时。 任何想法如何解决它?

func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
    let bezierPath = UIBezierPath()
    bezierPath.move(to: CGPoint(x: 40, y: 0))
    let shapeHeight: CGFloat = 40
    bezierPath.addQuadCurve(to: CGPoint(x: 40.0, y: shapeHeight), controlPoint: CGPoint(x: 100.0, y: shapeHeight/2.0))
    bezierPath.close()

    let shape = SKShapeNode(path: bezierPath.cgPath, centered: true)
    shape.isAntialiased = false
    shape.strokeColor = .white
    shape.fillColor = .clear
    shape.lineWidth = 2.0
    return shape
}

【问题讨论】:

  • 当一条线在路径上相交时,SKShapeNodes 会出现绘图问题,这可能就是您看到问题并需要附加附加点的原因。

标签: ios sprite-kit arkit skshapenode


【解决方案1】:

我不知道为什么会这样,但很容易解决:

    bezierPath.move(to: CGPoint(x: 40, y: 0))

    bezierPath.addLine(to:  CGPoint(x: 40.0001, y: 0)) //Add this line

    let shapeHeight: CGFloat = 40
    bezierPath.addQuadCurve(to: CGPoint(x: 40.0, y: shapeHeight), controlPoint: CGPoint(x: 100.0, y: shapeHeight/2.0))
    bezierPath.close()

【讨论】:

  • 好笑的苹果好笑!非常奇怪的行为并且非常有趣地知道为什么 40 不起作用但 40.0001 起作用。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多