I am new to iOS development (so please forgive my ineptitude - I searched everywhere!) And searched for a way to detect CAShapeLayer touch. So far I have come across hitTest . Is hitTest best method, and if so, how is it used in Swift, especially with CAShapeLayer s? Also, if I had a lot of CAShapeLayers , how would I use the hitTest method to reference them individually?
This is how I created CAShapeLayer :
let newBounds = CGRect(x: 0, y: 0, width: 200, height: 200) let newShape = CAShapeLayer() newShape.bounds = newBounds newShape.position = view.center newShape.cornerRadius = newBounds.width / 2 newShape.path = UIBezierPath(ovalInRect: newShape.bounds).CGPath newShape.lineWidth = 42 newShape.strokeColor = UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0).CGColor newShape.fillColor = UIColor.clearColor().CGColor newShape.strokeStart = 0.2 newShape.strokeEnd = 0.4 view.layer.addSublayer(newShape)
source share