override func touchesMoved(with event: NSEvent) { if(!isTracking) { return } let currentTouches = event.touches(matching: .touching, in: view) if(currentTouches.count != 2) { return } currentTouchOne = nil currentTouchTwo = nil currentTouches.forEach { (touch: NSTouch) in if(touch.identity.isEqual(initialTouchOne?.identity)) { currentTouchOne = touch } else { currentTouchTwo = touch } } let initialXPoint = [ initialTouchOne?.normalizedPosition.x ?? 0.0, initialTouchTwo?.normalizedPosition.x ?? 0.0 ].min() ?? 0.0 let currentXPoint = [ currentTouchOne?.normalizedPosition.x ?? 0.0, currentTouchTwo?.normalizedPosition.x ?? 0.0 ].min() ?? 0.0 let deviceWidth = initialTouchOne?.deviceSize.width ?? 0.0 let oldX = (initialXPoint * deviceWidth).rounded(.up) let newX = (currentXPoint * deviceWidth).rounded(.up) var delta: CGFloat = 0.0 if(oldX > newX) { // Swiping left delta = (oldX - newX) * -1.0 } else if(newX > oldX) { // Swiping right delta = newX - oldX } NSAnimationContext.runAnimationGroup { [weak self] (context: NSAnimationContext) in context.timingFunction = CAMediaTimingFunction(name: .easeIn) context.duration = 0.2 context.allowsImplicitAnimation = true self?.leftAnchor?.animator().constant = delta } }