Created
January 12, 2020 16:45
-
-
Save shawnbierman/a6f6ca55d89e615522f6f6b3c8da2f38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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