[Question] How to get svgAttributes from tapped layer?
glennposadas opened this issue · 1 comments
Is it possible to get svgAttributes from the tapped coordinates/layer?
Here's how I handle taps to color the tapped layer:
@objc private func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
let p: CGPoint = recognizer.location(in: self.svgImageView)
let layerHit = self.svgImageView.layer.hitTest(p)
for svgLayer in self.svgImageView.layer.sublayers! {
if svgLayer == layerHit! {
self.svgImageView.changeFillColorRecursively(sublayers: [layerHit!], color: .red)
}
}
}
I can't find a way or any properties of both the SVGImageView
object and any CALayer
property of SVGImageView
. When using SVGKit
library, I could get the data from the tapped layer BUT that library only reads "name" of each path. I added custom data to each path by the way, such as color.
Thank you!
You can access a layer's paths using https://github.com/pocketsvg/PocketSVG/blob/master/SVGLayer.h#L35 or https://github.com/pocketsvg/PocketSVG/blob/master/SVGImageView.h#L37 and from there get at the attributes.
The individual shape layers (sublayers of SVGLayer) do not have references to the actual SVGBezierPath objects. But the indices in svgLayer.sublayers, and svgLayer.paths should coincide, so you could probably get the tapped path that way