How to get rid of the status bar background on the UIWebView?

随声附和 提交于 2019-12-02 15:53:06

问题


Since iOS 11, when the UIWebView is full screen, a fake background appears on the status bar with the same color of the UIWebView background.

Anyone knows how to get rid of it?

Even adding the IUWebView to a storyboard and make it full screen will make the status bar background to appear

I've been trying to edit the size and some other properties of the UIWebView and none of them worked, but it's definitely something from the UIWebView. Also tried to see all the subviews and it's sizes and didn't see anything strange.

Attached a screenshot, see the grey "statusbar", it disappears when scrolling, and doesn't appear if the UIWebView is not over that part of the screen. I want it as on the second screenshot, only remove the fake background, not the status bar.


回答1:


This happens because of UIScrollView new behavior to adjust the content inset to include safe area insets like the status bar.

To fix it, just set it to UIScrollViewContentInsetAdjustmentNever

[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

Since iOS 11 Beta 4 you can add this to your viewport and will also remove the fake statusbar

viewport-fit=cover




回答2:


To do this entirely in HTML/CSS, viewport-fit=cover in the Viewport meta tag is the correct way to handle this.

But you'll also want to adjust your padding dynamically to handle the differently sized status bar on iPhone X with its notched camera/speaker.

Luckily, Apple exposed some CSS constants for the safe area insets, so you can take advantage of those in your CSS: i.e., padding-top: constant(safe-area-inset-top);

I wrote a bit more about this scenario and the new features for iOS 11 and iPhone X: https://ayogo.com/blog/ios11-viewport/




回答3:


Swift version:

webView.scrollView.contentInsetAdjustmentBehavior = .never


来源:https://stackoverflow.com/questions/44396880/how-to-get-rid-of-the-status-bar-background-on-the-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!