Disable scrolling of WKWebView in NSScrollView

Viewed 1651

I'd like to disable scrolling of my WKWebView that's inside a NSScrollView on macOS in Swift.

I found a way to disable scroll inside the WKWebView with css, tho the WKWebView still stops the NSScrollView from scrolling.

Dose anyone know how to do this?

2 Answers

Subclass WKWebView and implement the following method:

- (void)scrollWheel:(NSEvent *)event {
    // pass web view scroll events to the next responder. comment
    // this line out if you just want to disable scrolling 
    // altogether.
    //
    [[self nextResponder] scrollWheel:event];
}

Swift answer:

public class NoScrollWKWebView: WKWebView {
    public override func scrollWheel(with theEvent: NSEvent) {
        nextResponder?.scrollWheel(with: theEvent)
    }
}
Related