UIBezierPath 的 close() 函数不适用于 SKShapeNode
UIBezierPath's close() function doesn't work for SKShapeNode
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
}
我不知道为什么会这样,但是很容易修复:
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()
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
}
我不知道为什么会这样,但是很容易修复:
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()