ios - iOS 上的全屏 web 视图
问题描述
这显然是一件很容易做到的事情,但即使经过几天的敲打,我也无法做到。
我需要的是,当在 webview 上按下按钮时,我想让我的 webview 全屏显示。我需要隐藏状态栏和底栏才能完成全屏显示。状态栏区域的内容应该是可点击的。我的 webview 在 mainviewcontroller 上。我使用的是 XIB 而不是情节提要或 swiftUI。
我尝试过的是,我使用隐藏状态栏
UIApplication.shared.setStatusBarHidden(enable, with: UIStatusBarAnimation.slide)
我已经使用
func viewInset() -> (CGFloat, CGFloat) {
if #available(iOS 11.0, *) {
let insets = UIApplication.shared.keyWindow?.safeAreaInsets ?? .zero
return (max(insets.top, 20), max(insets.bottom, 20))
}
return (20.0, 20.0)
}
func enableFullScreen(enable: Bool) {
DispatchQueue.main.async {
let (topInset, bottomInset) = self.viewInset()
self.topConstraint.constant = enable ? -topInset : 0
self.bottomConstraint.constant = enable ? -bottomInset : 0
var contentInset = self.webView.scrollView.contentInset
contentInset.top = contentInset.top - topInset
contentInset.bottom = contentInset.bottom - bottomInset
self.webView.scrollView.contentInset = contentInset
UIApplication.shared.setStatusBarHidden(enable, with: UIStatusBarAnimation.slide)
}
}
红色边框是 webview。深蓝色/黑蓝色是我的内容。我的 webview 将背景颜色设置为绿色,如下图所示。
问题- 我无法让 webview 内容占据全屏,即包括绿色区域。绿色空间是 webview,因为我的背景颜色是绿色。即使我重新加载整个内容,内容也不会显示在那里。位于状态栏区域的任何内容都不可点击。
必须有更好的方法来全屏显示。有人可以建议吗?
请不要删除问题。让我知道如果没有提供任何细节,我会做的。
解决方案
推荐阅读
- algorithm - 需要算法来找到包含一组数字的最佳下限和上限
- exec - 如何在 godot 中使用不同的脚本执行其他脚本?
- mysql - 使用 MySQL / MySQLi 数据 - 每日、每周和每月图表
- wordpress - 站点健康中 Rest API 和 cURL 的 Wordpress 问题
- amazon-web-services - 如何在 AWS Cloud9 上更新编译器包含和链接器库路径
- c++ - 使用计算着色器更新实例数据
- javascript - 在 JavaScript 模块中使用 this
- python - 图像在事件中不会改变
- html - 如何在这个三角形内添加渐变
- php - 为什么包braintree/braintree_php 不显示表单paypal