Skip to content

Instantly share code, notes, and snippets.

@ryanmcgrath
Created December 3, 2018 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmcgrath/a98d6c839f57b6464f3b9862ed9f124c to your computer and use it in GitHub Desktop.
Save ryanmcgrath/a98d6c839f57b6464f3b9862ed9f124c to your computer and use it in GitHub Desktop.
override func touchesEnded(with event: NSEvent) {
if(self.isTracking) {
self.endTracking(leftAnchor?.constant ?? 0)
}
}
override func touchesCancelled(with event: NSEvent) {
if(self.isTracking) {
self.endTracking(leftAnchor?.constant ?? 0)
}
}
func endTracking(_ delta: CGFloat) {
initialTouchOne = nil
initialTouchTwo = nil
currentTouchOne = nil
currentTouchTwo = nil
isTracking = false
let leftThreshold: CGFloat = 50.0
let rightThreshold: CGFloat = -50.0
var to: CGFloat = 0.0
if(delta > leftThreshold) {
to = leftThreshold
} else if(delta < rightThreshold) {
to = rightThreshold
}
NSAnimationContext.runAnimationGroup { [weak self] (context: NSAnimationContext) in
context.timingFunction = CAMediaTimingFunction(name: .easeIn)
context.duration = 0.5
context.allowsImplicitAnimation = true
self?.leftAnchor?.animator().constant = to
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment