I ran into this same issue but I believe I found a simpler solution that doesn't involve deactivating and reactivating constraints.
Instead, call setNeedsLayout()
from the didFinish
navigation delegate method. This triggers another layout pass after the web view has finished loading:
override func viewDidLoad() {
super.viewDidLoad()
mainWebView.navigationDelegate = self
mainWebView.load(URLRequest(url: URL(string: "https://apple.com")!))
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.setNeedsLayout()
}
To ensure you're reliably reproducing the issue, you can slow the simulator animation to ensure the web view loads before the view controller finishes animating on screen.
Thank you @Stefan for pointing me in the right direction!