Skip to content

Instantly share code, notes, and snippets.

@shawnbierman
Created January 12, 2020 16:45
Show Gist options
  • Save shawnbierman/a6f6ca55d89e615522f6f6b3c8da2f38 to your computer and use it in GitHub Desktop.
Save shawnbierman/a6f6ca55d89e615522f6f6b3c8da2f38 to your computer and use it in GitHub Desktop.
import UIKit
import WebKit
class DetailViewController: UIViewController, WKNavigationDelegate {
var articleURLString: String!
let webView = WKWebView()
override func loadView() {
self.view = webView
webView.navigationDelegate = self
}
override func viewDidLoad() {
super.viewDidLoad()
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
if let url = URL(string: articleURLString) {
let request = URLRequest(url: url)
webView.load(request)
webView.allowsBackForwardNavigationGestures = true
}
}
override class func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
print(Float(webView.estimatedProgress))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment