I'd like to achieve the same effect as in Safari where the navigation bar changes slightly in color to reflect the web page that passes through while scrolling.
The 6 years old method that used to work with UIWebView is to simply include these two lines of code:
webView.scrollView.contentInset = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
webView.scrollView.scrollIndicatorInsets = _webView.scrollView.contentInset;
Since WKWebView the edge insets work much like content offset. It displays correctly initially but when you scroll the web page moves underneath the UINavigationBar/UIVisualEffectView making in it impossible to reach the top bar of websites that adjust accordingly, like at apple.com
Is there any other way?
The answers below are 6 years old and obsolete.
You need to move the web view under the navigation bar, and then set the web view's
contentInset
, like so: