Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import WebKit
- class HomePageVC: BaseVC, ControllerType {
- @IBOutlet weak var webViewContent: WKWebView!
- func initWebView() {
- self.webViewContent.scrollView.isScrollEnabled = false
- self.webViewContent.scrollView.bounces = false
- self.webViewContent.scrollView.bouncesZoom = false
- let contentHtml: String = "<html>......" // Change with content html
- // or change loadUrl not htmlString if needed
- self.webViewContent.loadHTMLString(resContent, baseURL: Bundle.main.bundleURL)
- self.webViewContent.tag = 0
- self.webViewContent.navigationDelegate = self // this needed to get navigation actions
- }
- }
- extension HomePageVC : WKNavigationDelegate {
- func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
- let idTag: Int = webView.tag
- switch idTag {
- case 0:
- // When webView loaded get the height of page from a JS command and use the height on constraint
- self.webViewContent.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
- if complete != nil {
- self.webViewContent.evaluateJavaScript("document.body.scrollHeight", completionHandler: { (height, error) in
- if let h = height as? CGFloat {
- self.heightConstrantWebViewcontainer.constant = h
- }
- })
- }
- })
- break
- case 1:
- let sz = self.newsMediaContainerView.frame.size
- webView.frame.size = sz
- break
- default:
- print("UnHandled webView[\(idTag)]")
- }
- }
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement