Ios 如何使用Swift从UIBezierPath创建虚线SKShapeNode?

Ios 如何使用Swift从UIBezierPath创建虚线SKShapeNode?,ios,swift,sprite-kit,skshapenode,Ios,Swift,Sprite Kit,Skshapenode,我找到的所有解释似乎都在说同样的话。我不明白这为什么不起作用 var linePath = UIBezierPath() linePath.move(to: CGPoint(x: 50, y: 50)) linePath.addLine(to: CGPoint(x: 100, y: 100)) var pattern : [CGFloat] = [10.0, 10.0] linePath.setLineDash(pattern, count: pattern.count, phase: 0)

我找到的所有解释似乎都在说同样的话。我不明白这为什么不起作用

var linePath = UIBezierPath()
linePath.move(to: CGPoint(x: 50, y: 50))
linePath.addLine(to: CGPoint(x: 100, y: 100))

var pattern : [CGFloat] = [10.0, 10.0]
linePath.setLineDash(pattern, count: pattern.count, phase: 0)
linePath.lineWidth = 10
linePath.lineCapStyle = .round

let shape = SKShapeNode()
shape.path = linePath.cgPath
shape.strokeColor = UIColor.white

self.addChild(shape)
此代码成功绘制了一条直线,但
形状
不继承
线路径
的虚线属性,甚至包括宽度。有什么想法吗

let linePath = UIBezierPath()
linePath.move(to: CGPoint(x: 50, y: 50))
linePath.addLine(to: CGPoint(x: 100, y: 100))

var pattern: [CGFloat] = [10.0, 10.0]
let dashed = CGPathCreateCopyByDashingPath (linePath.CGPath, nil, 0, pattern, 2)

var shape = SKShapeNode(path: dashed)
shape.strokeColor = UIColor.white

self.addChild(shape)
注意:在Swift 3中,
CGPathCreateCopyByDashingPath
已替换为
path.copy(dashingWithPhase:Length:)

e、 g

let dash=SKShapeNode(路径:linePath.cgPath.copy(dashingWithPhase:2,长度:pattern))

注意:在Swift 3中,
CGPathCreateCopyByDashingPath
已替换为
path.copy(dashingWithPhase:Length:)

e、 g

let dash=SKShapeNode(路径:linePath.cgPath.copy(dashingWithPhase:2,长度:pattern))