我正在尝试添加bezierPath作为视图的子层。
以下是我的代码
let arrPoints = Array(picture.points)
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: (arrPoints.first?.x.cgFloat()!)! * scaleX,
y: (arrPoints.first?.y.cgFloat()!)! * scaleY))
for index in 1...(arrPoints.count - 1) {
let point = arrPoints[index]
bezierPath.addLine(to: CGPoint(x: point.x.cgFloat()! * scaleX,
y: point.y.cgFloat()! * scaleY))
}
let shapeLayer = CAShapeLayer()
shapeLayer.path = bezierPath.cgPath
shapeLayer.strokeColor = UIColor(hexString: picture.color)!.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = picture.brushSize.cgFloat()!
let viewSymbol = SVGImageView(frame: CGRect(origin: origin, size: size))
viewSymbol.accessibilityHint = "Brush"
viewSymbol.isUserInteractionEnabled = true
viewSymbol.alpha = picture.alpha.cgFloat()!
viewSymbol.layer.insertSublayer(shapeLayer, at: 0)
viewSymbol.backgroundColor = UIColor(hexString: "#dfdfdf", transparency: 0.25)
viewLayerActive!.addSubview(viewSymbol)
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
viewSymbol.addGestureRecognizer(panGesture)
此外,所附图像显示了我当前实施的结果,其中右侧的蓝色轮廓框是子层,Szpilman
上方的LightGray框是我要向其添加子层的视图
如何将子图层完全添加到灰色框中?