Here is the best solution in my opinion:
Swift 4
import Cocoa @IBDesignable @objc(BCLDisablableScrollView) public class DisablableScrollView: NSScrollView { @IBInspectable @objc(enabled) public var isEnabled: Bool = true public override func scrollWheel(with event: NSEvent) { if isEnabled { super.scrollWheel(with: event) } else { nextResponder?.scrollWheel(with: event) } } }
Just replace any NSScrollView with DisablableScrollView (or BCLDisablableScrollView if you are still using ObjC) and you're done. Just install isEnabled in code or in IB, and it will work as expected.
The main advantage it has for nested scroll views; disabling children without sending an event to the next respondent will also effectively disable parents when the cursor is over a disabled child.
Here are all the benefits of this approach, listed:
- β
disables scrolling
- β
does it programmatically, behaves normally by default
- β
does not interrupt the scrolling of the parent view
- Interface Developer Integration
- β
Plug-in replacement for
NSScrollView - β
Swift and Objective-C compatible
Ben leggiero
source share