调用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
相关产品推荐
相关产品推荐

