macOS, Swift
Is it possible to remove the scroll in WebKit View? (or make it not visible)
I have a WebKit View from library and I have made the connection to the ViewController.swift:
@IBOutlet weak var webView1: WKWebView!
In MacOS, I tested this:
Subclass and implement scrollWheel:
func scrollWheel(with event: NSEvent)
https://stackoverflow.com/questions/43961952/disable-scrolling-of-wkwebview-in-nsscrollview
See here
openradar.appspot.com/51328335
Code is
import Cocoa
import WebKit
class MyWKWebView: WKWebView {
override func scrollWheel(with event: NSEvent) {
print("NoScroll") // Just to see scroll did not occur
}
}
class WebViewController: NSViewController, WKUIDelegate {
var webView: MyWKWebView!
override func loadView() {
super.loadView()
let webConfiguration = WKWebViewConfiguration()
webView = MyWKWebView(frame: CGRect(x: 0, y: 0, width: 300, height: 300), configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
var myURL: URL!
myURL = URL(string: "https://developer.apple.com/")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
webView.allowsMagnification = true
webView.magnification = 0.25
webView.setMagnification(0.25, centeredAt: CGPoint(x: 150, y: 150))
}
}