[SWIFT] In iOS14 (xcode12 build), if the contentInset.top of WKWebView is set to a certain value or more, the bug that scrolls to the bottom while loading webView for some reason?

It is a report because a bug-like behavior has occurred in the build with iOS14 + xcode12.

** If you set the contentInset.top of WKWebView to a certain value or more, Somehow scrolled to the bottom while loading webView **

It will be something like that.

I have confirmed that a constant value occurs around 700 to 800. It does not occur with 500 or something

Below is the reproduction code I also made a storyboard in advance that just placed WKWebView on the entire surface.


class ViewController: UIViewController {
    @IBOutlet weak var webView: WKWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        let url = URL(string: "https://cookpad.com")!
        
        let request = URLRequest(url: url)
        
        webView.load(request)
        
        webView.scrollView.contentInset.top = 800.0

        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            self.webView.reload()
        }
    }
}

When I run it, it loads with scrolling to the bottom for some reason. Same after reloading.

Example:

However, there are some pages that are loaded properly at the top for the first time, perhaps because it is a light page or there are some conditions. (Google.co.jp etc.) However, even in that case, after reload (), it will be scrolled to the bottom.

It's a bug-like behavior of iOS14SDK, but it's a report.

If you have a workaround, please let me know!

Recommended Posts

In iOS14 (xcode12 build), if the contentInset.top of WKWebView is set to a certain value or more, the bug that scrolls to the bottom while loading webView for some reason?
Determine that the value is a multiple of 〇 in Ruby
I can't build if I set the build destination to a simulator with XCode12!