加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift3 – CGPath在Swift 3中不起作用

发布时间:2020-12-14 02:29:15 所属栏目:百科 来源:网络整理
导读:参见英文答案 1. CGPathMoveToPoint’ is unavailable: Use move(to:transform:) 2. ‘CGPathAddLineToPoint’ is unavailable: Use addLine(to:transform:)1个 我正在更新swift 3的代码.我已经为swift 2中的spritekit对象创建了一个自定义路径.但是,现在我
参见英文答案 > 1. CGPathMoveToPoint’ is unavailable: Use move(to:transform:) 2. ‘CGPathAddLineToPoint’ is unavailable: Use addLine(to:transform:)1个
我正在更新swift 3的代码.我已经为swift 2中的spritekit对象创建了一个自定义路径.但是,现在我得到一个编译器错误:

Nil is not compatible with expected argument type ‘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,0 - offsetY)
CGPathAddLineToPoint(path,24 - offsetX,28 - offsetX,40 - offsetY)
CGPathAddLineToPoint(path,18 - offsetX,46 - offsetY)
CGPathAddLineToPoint(path,6 - offsetX,36 - offsetY)
CGPathAddLineToPoint(path,18 - offsetY)



path.closeSubpath()

错误是在添加到路径时在第二个参数中传递nil.我尝试传入一个不安全的指针,如下所示:

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

但后来又有了一个奇怪的错误.

CGPathMoveToPoint is unavailable. Use move(to: transform:)

但是,没有带参数名称的移动函数.然而,有一个举动(toParent:).

大多数语法在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))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读