Created
December 3, 2018 09:31
-
-
Save ryanmcgrath/a98d6c839f57b6464f3b9862ed9f124c to your computer and use it in GitHub Desktop.
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 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