-
-
Save anupamchugh/110a627100c123841a18611356edfa58 to your computer and use it in GitHub Desktop.
This file contains 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
let overlay = UIView() | |
var lastPoint = CGPoint.zero | |
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { | |
clearOverlay() | |
if let touch = touches.first { | |
lastPoint = touch.location(in: self.view) | |
} | |
} | |
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { | |
if let touch = touches.first { | |
let currentPoint = touch.location(in: view) | |
drawSelectionArea(fromPoint: lastPoint, toPoint: currentPoint) | |
} | |
} | |
func drawSelectionArea(fromPoint: CGPoint, toPoint: CGPoint) { | |
let rect = CGRect(x: min(fromPoint.x, toPoint.x), y: min(fromPoint.y, toPoint.y), width: abs(fromPoint.x - toPoint.x), height: abs(fromPoint.y - toPoint.y)) | |
overlay.frame = rect | |
} | |
func clearOverlay(){ | |
overlay.isHidden = false | |
overlay.frame = CGRect.zero | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment