Blurry translucent effect of UINavigationBar/UIVisualEffectView while scrolling on a WKWebView?

905 views Asked by At

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.

enter image description here

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.

2

There are 2 answers

1
jjv360 On

You need to move the web view under the navigation bar, and then set the web view's contentInset, like so:

navBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44);
webView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
webView.scrollView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);
webView.scrollView.scrollIndicatorInsets = webView.scrollView.contentInset;
0
Laur Stefan On

Go to you app setting in xcode and in Status Bar Style click the drop down and select "Light". These should apply in all your app