如何防止关闭贝塞尔路径 [英] How can I prevent closing Bezier Path

查看:22
本文介绍了如何防止关闭贝塞尔路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create a Bezier curve, and create a collision boundary for my object.

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

the same poor result I get, if I choose addArcWithCente

line.moveToPoint(firstSurfacePoint)
line.addArcWithCenter(center, radius: radius, startAngle: CGFloat(M_PI), endAngle: CGFloat(M_PI/2), clockwise: false)
line.addLineToPoint(fourthSurfacePoint)

在这两次尝试中收到了奇怪的结果,这是至关重要的,因为我无法创建正确的碰撞.在第一次尝试中,我的对象穿过路径,就好像它是从 firstPoint 到第三点的直线,以及在第二个

In this two tries receive a strange results, that are crucial, as I can't create a proper collision. In the first attempt my object goes through path as if it is a straight line from firstPoint to thirdPoint, as well as in the second

我做错了什么?

我的图(没有弧线)

我的图(带弧)

推荐答案

currentPath.fillColor = nil

currentPath.fillColor = UIColor.clearColor().CGColor

这篇关于如何防止关闭贝塞尔路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆