// // KMToolSetScroller.swift // PDF Reader Pro // // Created by wanjun on 2022/10/27. // import Cocoa class KMToolSetScroller: NSScroller { var newScroolValue: Float = 0 override var floatValue: Float { didSet { animator().alphaValue = 1.0 NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(fadeOut), object: nil) perform(#selector(fadeOut), with: nil, afterDelay: 1.5) } } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) self.drawKnob() } override func drawKnobSlot(in slotRect: NSRect, highlight flag: Bool) { } override init(frame frameRect: NSRect) { super.init(frame: frameRect) commonInitializer() } required init?(coder: NSCoder) { super.init(coder: coder) commonInitializer() } override func awakeFromNib() { super.awakeFromNib() commonInitializer() } // MARK: func commonInitializer() { let trackingArea: NSTrackingArea = NSTrackingArea( rect: self.bounds, options: [.mouseEnteredAndExited, .activeInActiveApp, .mouseMoved], owner: self, userInfo: nil ) addTrackingArea(trackingArea) } @objc func fadeOut() { NSAnimationContext.runAnimationGroup({ (context) in context.duration = 0.3 animator().alphaValue = 0.0 }, completionHandler: nil) } override func mouseExited(with event: NSEvent) { super.mouseExited(with: event) fadeOut() } override func mouseEntered(with event: NSEvent) { super.mouseEntered(with: event) NSAnimationContext.runAnimationGroup({ (context) in context.duration = 0.1 animator().alphaValue = 1.0 }, completionHandler: nil) NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(fadeOut), object: nil) } override func mouseMoved(with event: NSEvent) { super.mouseMoved(with: event) alphaValue = 1.0 } override class var isCompatibleWithOverlayScrollers: Bool { return self == KMToolSetScroller.self } }