Disable scrolling of WKWebView in NSScrollView
Asked Answered
T

2

6

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?

Taraxacum answered 14/5, 2017 at 8:36 Comment(0)
U
10

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];
}
Universalize answered 19/1, 2018 at 19:6 Comment(1)
That is probably the only working solution for WKWebView on macOSColvert
N
1

Swift answer:

public class NoScrollWKWebView: WKWebView {
    public override func scrollWheel(with theEvent: NSEvent) {
        nextResponder?.scrollWheel(with: theEvent)
    }
}
Normalize answered 1/3, 2021 at 21:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.