CGPath在Swift 3中不起作用

帕特里克

我正在更新swift 3的代码。我为在swift 2中工作的spritekit对象创建了一个自定义路径。但是,现在出现编译器错误:

Nil与预期的参数类型'Unsafe Pointer CGAffineTransform'不兼容

let offsetX = player.size.width * player.anchorPoint.x
let offsetY = player.size.height * player.anchorPoint.y

let path = CGMutablePath()

CGPathMoveToPoint(path, nil, 10 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 10 - offsetX, 0 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 0 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 28 - offsetX, 40 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 46 - offsetY)
CGPathAddLineToPoint(path, nil, 6 - offsetX, 36 - offsetY)
CGPathAddLineToPoint(path, nil, 6 - offsetX, 18 - offsetY)



path.closeSubpath()

错误是在添加到路径时在第二个参数中传递nil。我试图这样传递不安全的指针:

var tr = CGAffineTransform.identity
CGPathMoveToPoint(path, &tr, 10 - offsetX, 16 - offsetY)
....

但随后又出现了另一个奇怪的错误。

CGPathMoveToPoint不可用。使用move(to:transform :)

但是,没有带有名称为to的move函数。但是有一个动作(到Parent :)。

纳塔拉然

在Swift 3中,大多数语法都进行了更改,但是它们并没有删除任何API方法(例如CGPathMoveToPoint),只是像下面这样重命名。

let path = CGMutablePath()
path.move(to: CGPoint(x: 10.0, y: 10.0))
path.addLine(to: CGPoint(x: 10.0, y: 10.0))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章