Created
August 2, 2017 15:39
-
-
Save codePrincess/7a3fdd1675a4a3e106d9eee9aaca3b6d to your computer and use it in GitHub Desktop.
Smooth doodling with coalesced touches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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