You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用UIBezierPath.currentPoint触发CGPathGetCurrentPoint无当前点错误排查

关于UIBezierPath.currentPoint引发的CGPathGetCurrentPoint: no current point错误疑问

调用以下Swift函数时,控制台输出错误CGPathGetCurrentPoint: no current point:

func getPositionFor(_ node: SKSpriteNode, orPath: UIBezierPath) -> CGPoint {
    
    var thePosition = CGPointZero

    print("here1")   // (1)

    if let theCurrentPoint = orPath.currentPoint as CGPoint? {
        print("\(theCurrentPoint)")   // (3)
        thePosition = theCurrentPoint
    }
    else {
        thePosition = node.position
    }

    print("here2")   // (2)

    return thePosition
    
}   // getPositionFor

通过打印日志排查得到以下结果:

  • 仅保留print("here1")时,控制台输出:
here1
CGPathGetCurrentPoint: no current point.
  • 仅保留print("here2")时,控制台输出:
CGPathGetCurrentPoint: no current point.
here2
  • 仅保留print("\(theCurrentPoint)")时,控制台输出:
CGPathGetCurrentPoint: no current point.
(0.0, 0.0)

可以确定错误产生于if let theCurrentPoint = orPath.currentPoint as CGPoint?条件绑定语句,但按逻辑,当路径没有当前点时应该执行else分支,实际却进入了if分支并输出(0.0, 0.0),对此存在疑问。

内容的提问来源于stack exchange,提问作者user22530416

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 01:17:03