You can change the end points of a line. Here’s how to attach one to a pan gesture, and then toggle it’s visibility depending on the state of the gesture.
This example uses
if-else
instead ofswitch
, just because we can.
let line = Line((Point(), Point()))
line.endPoints.0 = canvas.center
line.lineWidth = 40.0
canvas.addPanGestureRecognizer { locations, center, translation, velocity, state in
line.endPoints.1 = center
if state == .Began {
self.canvas.add(line)
} else if state == .Ended {
self.canvas.remove(line)
}
}