ios - UIBezierPath 的 close() 函数不适用于 SKShapeNode
问题描述
close() 函数应该在子路径的第一个点和最后一个点之间创建一条线段。它在 Playground 中工作,但在我使用 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()
推荐阅读
- django - Redis 服务器未在 Windows 10 上启动
- java - 如何防止 Spring Data JPA 中的自动更新?
- directx-11 - D3D11 - 如何在没有 Windows 10 的情况下在显示器上启用 HDR
- html - 如何使用物化 CSS 使表单在从应用程序打开时响应手机
- xcode - SwiftUI ScrollView 总是没有 ResponsiveScrolling
- html - 向 html 表单添加条件`
- c - 使用数组时后缀/前缀如何工作
- css - 继承时的转换行为
- c++ - 断开设备与 PC 后如何避免睡眠模式问题?
- flutter - 为什么每个与 font_awesome_flutter 包相关的代码都会报错,包括导入包代码?