I\'m using an NSSlider control, and I\'ve configured it to use continuous mode so that I can continually update an NSTextField with the current value of the slider while the
Took me a little while to find this thread, but the accepted answer (although old) is great for detecting NSSlider state changes (slider value stopped changing being the main one I was looking for)!
Answer in Swift (Swift 4.1):
let slider = NSSlider(value: 1,
minValue: 0,
maxValue: 4,
target: self,
action: #selector(sliderValueChanged(sender:)))
. . .
@objc func sliderValueChanged(sender: Any) {
guard let slider = sender as? NSSlider,
let event = NSApplication.shared.currentEvent else { return }
switch event.type {
case .leftMouseDown, .rightMouseDown:
print("slider value started changing")
case .leftMouseUp, .rightMouseUp:
print("slider value stopped changing: \(slider.doubleValue)")
case .leftMouseDragged, .rightMouseDragged:
print("slider value changed: \(slider.doubleValue)")
default:
break
}
}
Note: the right event types account for someone who has reversed their mouse buttons