Swift-删除相交线

问题描述 投票:0回答:1

帮助!如何删除相交线,这样我将只有外部形状?

enter image description here

我需要对此进行哪些更改以删除相交的线?

let width = 300
func circle(withRadius radius: CGFloat) -> UIView {
    let path = UIBezierPath(arcCenter: CGPoint(x: width * (1/2), y: width * (1/3)), radius: 80, startAngle: .zero, endAngle: .pi * 2, clockwise: true)
    path.append(UIBezierPath(arcCenter: CGPoint(x: width * (1/3), y: width * (2/3)), radius: 80, startAngle: .zero, endAngle: .pi * 2, clockwise: true))
    path.append(UIBezierPath(arcCenter: CGPoint(x: width * (2/3), y: width * (2/3)), radius: 80, startAngle: .zero, endAngle: .pi * 2, clockwise: true))

    let shapeLayer = CAShapeLayer()
    shapeLayer.path = path.cgPath
    shapeLayer.fillColor = UIColor.clear.cgColor
    shapeLayer.strokeColor = UIColor.black.cgColor
    shapeLayer.lineWidth = 3.0

    backView.layer.addSublayer(shapeLayer)
    return backView
}
swift uiview draw
1个回答
0
投票

一种方法是通过计算圆切开的3个外部点的位置。 (该点在图像中以红色圈出)。enter image description here

然后您计算这些点的中心(我们将此点称为中心)。之后,您要计算一个外部点与中心之间的距离(我们将此距离称为半径)。然后,您可以在中心使用我们之前找到的半径创建一个椭圆。该椭圆必须与背景颜色相同,并且其zPosition必须大于其他3个圆圈。完成后,相交线现在消失了:)

((如果您不知道如何创建椭圆,这是一个可以帮助您的脚本:)

let circle = SKShapeNode(circleOfRadius: radius)
circle.position = center
circle.zPosition = 100 //Need to be greater than the others zPosition
self.addChild(circle)
© www.soinside.com 2019 - 2024. All rights reserved.