0

Summary

As of current, my WKWebView is having some minor scrolling issues. It is hiding the very bottom of the web page. This happens until the user scrolls all the way down the embedded scroll view within the web page.

When the WebView is scrolled at the top of the page, it shows the top bar of the web page; whereas when it is scrolled to the bottom of the page, it shows the bottom bar of the web page. Safari for iOS seems to fit the web page content perfectly, however.

My WKWebView vs. Safari's WKWebView Comparison

As you can see, Safari's WKWebView allows for both of the top and bottom bars to be visible at all times. How do I go about doing this with my application?

ViewController.swift

import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate, UIScrollViewDelegate {

    var webView: WKWebView!
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.navigationDelegate = self
        self.view = webView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let webPlayer = URL(string: "http://web.alizarin.ca")
        let webRequest = URLRequest(url: webPlayer!)
        webView.load(webRequest)
        webView.allowsBackForwardNavigationGestures = true
        
        webView.scrollView.delegate = self
        webView.scrollView.bounces = false
        
        webView.scrollView.contentSize = webView.bounds.size
    }
    
    // Disable Zoom for WebView
    func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
        return nil
    }
}

Side note: I have tried commenting out every UIScrollView line of code, and still nothing.

halfer
  • 19,824
  • 17
  • 99
  • 186
JDev
  • 5,168
  • 6
  • 40
  • 61
  • 2
    I know for a fact there is a difference between using WKWebView and what Safari uses (APIs available to apple developer only). I do have a suggestion but it might be a long shot though. I had a similar issue with the website content not fitting correctly and I did something similar to this answer: http://stackoverflow.com/a/26583062/2617369. Hope it helps – Prientus Dec 15 '16 at 03:30
  • Thank you so much for this! Will look into it. – JDev Dec 16 '16 at 18:25

0 Answers0