Skip to content

Instantly share code, notes, and snippets.

@almaleh
Created January 16, 2019 04:33
Show Gist options
  • Save almaleh/926378763df622f2671237797c15d0f3 to your computer and use it in GitHub Desktop.
Save almaleh/926378763df622f2671237797c15d0f3 to your computer and use it in GitHub Desktop.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let newTouchPoint = touches.first?.location(in: self) else { return }
var lastTouchPoint: CGPoint = .zero
if let lastIndex = lines.indices.last {
// get reference to last point
if let lastPoint = lines[lastIndex].last { lastTouchPoint = lastPoint }
// add new point
lines[lastIndex].append(newTouchPoint)
}
let rect = calculateRectBetween(lastPoint: lastTouchPoint, newPoint: newTouchPoint)
setNeedsDisplay(rect)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment