To do this entirely in HTML/CSS (which would involve you having control over the HTML), you'd want to add viewport-fit=cover
to the meta viewport
tag. This tells the device that you want the webview to fill the entire screen, including "safe areas" (such as behind the status bar).
But you'll also want to adjust your padding dynamically to handle the iPhone X, which has a larger status bar area and includes a notch for the speaker and camera.
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 CSS features for iOS 11 and iPhone X: https://ayogo.com/blog/ios11-viewport/
If you don't have control over the HTML/CSS being loaded, then you can disable the safe area behaviour for your web view:
if #available(iOS 11.0, *) {
webView.scrollView.contentInsetAdjustmentBehavior = .never;
}
Note that on iPhone X this might cause content to be inaccessible and obscured by the notch.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…