【发布时间】:2018-07-15 15:27:27
【问题描述】:
我相信这可能是一个 iOS 错误,我已通过错误报告向 Apple 报告了它。如果有一些我可以使用的解决方法或解释原因,我会在这里发布。
我想在 SceneKit 中绘制 UIBezierPath 的笔触。我正在使用 CGPath copyStrokingWithWidth 函数,然后使用给定的路径创建一个 SCNShape。
这适用于具有 2 点的线条,但在具有 3 点的线条上,SCNShape 不显示任何内容。我已经确定只有lineWidth 大于 0.1 时才会出现这种情况。将lineWidth 设置为 0.1,它可以完美显示。
let strokeBezierPath = UIBezierPath()
strokeBezierPath.lineWidth = 1
strokeBezierPath.move(to: CGPoint.zero)
strokeBezierPath.addLine(to: CGPoint(x: 10, y: 0))
strokeBezierPath.addLine(to: CGPoint(x: 10, y: 10))
let cgPath = strokeBezierPath.cgPath.copy(
strokingWithWidth: strokeBezierPath.lineWidth,
lineCap: strokeBezierPath.lineCapStyle,
lineJoin: strokeBezierPath.lineJoinStyle,
miterLimit: strokeBezierPath.miterLimit)
let bezierPath = UIBezierPath(cgPath: cgPath)
let shape = SCNShape(path: bezierPath, extrusionDepth: 1)
shape.firstMaterial?.diffuse.contents = UIColor.blue
let node = SCNNode(geometry: shape)
node.position.z = -40
sceneView.scene.rootNode.addChildNode(node)
这适用于:
- 仅前 2 点
- 0.1 的线宽
- 人工绘制的覆盖同一区域的贝塞尔路径
将线宽的 UIBezierPath 打印为 0.1(显示):
<UIBezierPath: 0x1d00b12e0; <MoveTo {0, 0.050000000000000003}>,
<LineTo {10, 0.050000000000000003}>,
<LineTo {9.9499999999999993, 10}>,
<LineTo {10.050000000000001, 10}>,
<LineTo {10.050000000000001, 0}>,
<LineTo {0, -0.050000000000000003}>,
<LineTo {0, 0.050000000000000003}>,
<Close>
线宽为0.2(不显示):
<UIBezierPath: 0x1d00b7160; <MoveTo {0, 0.10000000000000001}>,
<LineTo {10, 0.10000000000000001}>,
<LineTo {9.9000000000000004, 0}>,
<LineTo {9.9000000000000004, 10}>,
<LineTo {10.1, 10}>,
<LineTo {10.1, 0}>,
<LineTo {10, -0.10000000000000001}>,
<LineTo {0, -0.10000000000000001}>,
<LineTo {0, 0.10000000000000001}>,
<Close>
【问题讨论】:
标签: ios core-graphics scenekit uibezierpath arkit