iOS 11 UIWebView pop down by status bar

user5612625 picture user5612625 · Aug 13, 2017 · Viewed 7.1k times · Source

In iOS 11, UIWebView is pop down by status bar. It may be affected by safe area inset introduced by iOS 11. I try to set the property contentInsetAdjustmentBehavior as below:

webView.scrollowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways

It works. However, for some page using -webkit-overflow-scrolling, webView.scrollowView has another UIScrollowView(UIWebOverflowScrollView) as its subview. If I do not set the property contentInsetAdjustmentBehavior for that scrollView, the page elements will sink. If any other solution for this issue without setting the property contentInsetAdjustmentBehavior for all the scrollView of UIWebview.

Answer

user5612625 picture user5612625 · Aug 31, 2017

Actually, I create a fullscreen webView with navigationBar hidden but statusBar not hidden. For WKWebView, Apple has fixed the bug here https://github.com/WebKit/webkit/commit/cb45630904c7655cc3fb41cbf89db9badd1ef601 since iOS 11 beta 8, so we can set the property contentInsetAdjustmentBehavior of wkWebView.scrollview:

wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever

For UIWebView(Apple has abandoned UIWebView), we can adjust the safearea of UIViewController by setting the property additionalSafeAreaInsets of rootViewController(yes, only the additionalSafeAreaInsets of rootViewController works):

navigationController.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);

or the frame of uiWebView:

uiWebView.frame = CGRectMake(0.0, -20, uiWebView.frame.size.width, uiWebView.frame.size.height + 20);