Last active
January 17, 2020 12:35
-
-
Save yfujiki/02256aa666dcf2918e6acdd730e55db7 to your computer and use it in GitHub Desktop.
SracthCard Touch Handling
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
private var previousLocation: CGPoint? | |
// 0. Line/LineCollection class is a convenience class to store line(s) | |
private var lineCollection: LineCollection = LineCollection() | |
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { | |
// 1. If there is no touch point or if the point did not move, ignore | |
guard let touch = touches.first else { | |
return | |
} | |
let location = touch.location(in: self) | |
if location == previousLocation { | |
return | |
} | |
if previousLocation == nil{ | |
// 2. If this is the first touch point, then create first line with the point | |
let line = Line().lineByAdding(point: location) | |
lineCollection = lineCollection.lineCollectionByAddingLine(line: line) | |
} else { | |
// 3. If this is the second touch point and on, just add the point to the line collection | |
lineCollection = lineCollection.lineCollectionByAddingPoint(point: location) | |
} | |
previousLocation = location | |
} | |
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { | |
// 4. reset previousLocation | |
previousLocation = nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment