I\'m quite new to iOS Development (so please forgive my ineptitude - I\'ve looked everywhere!), and was looking to find a way to detect a tap on a CAShapeLayer.
Swift 4 & 5
My UIImageView has multiple embedded CAShapeLayer objects. Here is how I was able to detect taps on them. Referenced from this tutorial.
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
let touch = touches.first
guard let point = touch?.location(in: imageView) else { return }
guard let sublayers = imageView.layer.sublayers as? [CAShapeLayer] else { return }
for layer in sublayers {
if let path = layer.path, path.contains(point) {
print(layer)
}
}
}