Swift 如何防止关闭贝塞尔路径

Swift 如何防止关闭贝塞尔路径,swift,uibezierpath,cgpoint,Swift,Uibezierpath,Cgpoint,我想创建一条贝塞尔曲线,并为我的对象创建一个碰撞边界 let firstSurfacePoint = CGPoint(x: 30, y: 120) let secondSurfacePoint = CGPoint(x: 20, y: 200) let thirdSurfacePoint = CGPoint(x: 200, y: 300) let center = CGPoint(x: 150, y: 120) let radius: CGFloat = 120.00 let arcWidth:

我想创建一条贝塞尔曲线,并为我的对象创建一个碰撞边界

let firstSurfacePoint = CGPoint(x: 30, y: 120)
let secondSurfacePoint = CGPoint(x: 20, y: 200)
let thirdSurfacePoint = CGPoint(x: 200, y: 300)

let center = CGPoint(x: 150, y: 120)
let radius: CGFloat = 120.00
let arcWidth: CGFloat = 20.00    
let fourthSurfacePoint = CGPoint(x: 240, y: 300)

func createCollisionPath(collision: UICollisionBehavior) {

    let line =  UIBezierPath()

    line.moveToPoint(firstSurfacePoint)
    line.addCurveToPoint(thirdSurfacePoint, controlPoint1: secondSurfacePoint, controlPoint2: secondSurfacePoint)
    line.addLineToPoint(fourthSurfacePoint)

    let currentPath = CAShapeLayer()
    currentPath.path = line.CGPath
    currentPath.strokeColor = UIColor.blackColor().CGColor
    currentPath.fillColor = UIColor.clearColor().CGColor
    currentPath.lineWidth = 1
    view.layer.addSublayer(currentPath)

    collision.addBoundaryWithIdentifier("curve", forPath: line)

}
如果我选择addArcWithCente,我会得到同样糟糕的结果

line.moveToPoint(firstSurfacePoint)
line.addArcWithCenter(center, radius: radius, startAngle: CGFloat(M_PI), endAngle: CGFloat(M_PI/2), clockwise: false)
line.addLineToPoint(fourthSurfacePoint)
在这两次尝试中,我得到了一个奇怪的结果,这是至关重要的,因为我无法创建一个正确的碰撞。在第一次尝试中,我的对象穿过路径,就像它是一条从第一个点到第三个点的直线一样,在第二个点中也是如此

我做错了什么


谢谢,这很有效,但不是我想象的那样。主要问题仍然存在。它不会通过这条线创建边界。我的对象仍然通过路径,就像它是从第一个点到第三个点的直线一样。是否确实已将移动对象添加到
UICollectionBehavior
?如果有帮助的话,你可以在这里找到一个很棒的教程
currentPath.fillColor = nil
currentPath.fillColor = UIColor.clearColor().CGColor