iOS 11 UIWebView按状态栏弹出

4 uiwebview uiscrollview uistatusbar ios11

在iOS 11中,UIWebView由状态栏弹出.它可能会受到iOS 11引入的安全区域插入的影响.我尝试将属性contentInsetAdjustmentBehavior设置如下:

webView.scrollowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways
Run Code Online (Sandbox Code Playgroud)

有用.但是,对于某些使用-webkit-overflow-scrolling的页面,webView.scrollowView将另一个UIScrollowView(UIWebOverflowScrollView)作为其子视图.如果我没有为该scrollView设置属性contentInsetAdjustmentBehavior,则页面元素将下沉.如果没有为UIWebview的所有scrollView设置属性contentInsetAdjustmentBehavior,则为此问题提供任何其他解决方案.

小智 17

实际上,我创建了一个全屏webView,其中navigationBar已隐藏,但statusBar未隐藏.对于WKWebView,Apple已经修复了自iOS 11 beta 8以来的错误https://github.com/WebKit/webkit/commit/cb45630904c7655cc3fb41cbf89db9badd1ef601,因此我们可以设置wkWebView.scrollview的属性contentInsetAdjustmentBehavior:

wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever
Run Code Online (Sandbox Code Playgroud)

对于UIWebView(Apple放弃了UIWebView),我们可以通过设置rootViewController 的属性additionalSafeAreaInsets来调整UIViewController的安全区域(是的,只有rootViewController的additionalSafeAreaInsets工作):

navigationController.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

或者uiWebView的框架:

uiWebView.frame = CGRectMake(0.0, -20, uiWebView.frame.size.width, uiWebView.frame.size.height + 20);
Run Code Online (Sandbox Code Playgroud)