Skip to content

Instantly share code, notes, and snippets.

@codePrincess
Created August 2, 2017 15:39
Show Gist options
  • Save codePrincess/7a3fdd1675a4a3e106d9eee9aaca3b6d to your computer and use it in GitHub Desktop.
Save codePrincess/7a3fdd1675a4a3e106d9eee9aaca3b6d to your computer and use it in GitHub Desktop.
Smooth doodling with coalesced touches
override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
let context = UIGraphicsGetCurrentContext()
image?.draw(in: bounds)
var touches = [UITouch]()
if let coalescedTouches = event?.coalescedTouches(for: touch) {
touches = coalescedTouches
} else {
touches.append(touch)
}
for touch in touches {
drawStroke(context: context, touch: touch)
}
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment