I am trying to add a bezierPath as a sublayer of a view.
Following is my code
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)
Also, the attached image shows the result of my current implementation where the blue outlined box to the right is the sublayer and the LightGray box over Szpilman
is the view to which Iām adding the sublayer
How can I add the sublayer exactly into the gray box?