Author
Travis Kirton


Dynamic Line End Points

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 of switch, just because we can.

Example

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)
    }
}