我在WebKit iOS11.2中使用了这个代码,我的谷歌地图框架不能显示在屏幕上,就像这样,我附上了截图。
let topBarHeight = UIApplication.shared.statusBarFrame.size.height +
(self.navigationController?.navigationBar.frame.height ?? 0.0)
webView.frame = CGRect.init(x: 0, y: topBarHeight + 20, width: self.view.frame.width, height: self.view.frame.height - topBarHeight)
self.view.addSubview(webView)
self.navigationController?.isNavigationBarHidden = true
webView.backgroundColor = UIColor.clear
webView.scrollView.isScrollEnabled = false
webView.scrollView.bounces = false
webView.loadHTMLString("<html><body><iframe width=\"\(self.webView.frame.size.width)\" height=\"\(self.webView.frame.size.height-70)\" frameborder=\"0\" style=\"border:0\" src=\"https://www.google.com/maps/embed/v1/place?key=\(GoogleApikey)&q=\(Company.Instance.shopAddress),\(Company.Instance.shopName)\"allowfullscreen></iframe></body></html>", baseURL: nil)

发布于 2019-09-17 17:11:46
在viewDidLoad()中没有完全设置约束。您应该将代码移动到其他生命周期方法中,如viewDidAppear(),并使用以下HTML加载它
webView.loadHTMLString("<html><body><iframe frameborder=\"0\" style=\"border:0;width: 100%;height:100%\" src=\"https://www.google.com/maps/embed/v1/place?key=\(GoogleApikey)&q=\(Company.Instance.shopAddress),\(Company.Instance.shopName)\"allowfullscreen></iframe></body></html>", baseURL: nil)发布于 2019-09-17 16:54:45
你在哪里添加你的地图?
您可以尝试将其添加到函数viewDidLoad中。例如:
override func viewDidLoad() {
super.viewDidLoad()
webView.frame = CGRect.init(x: 0, y: topBarHeight + 20, width: self.view.frame.width, height: self.view.frame.height - topBarHeight)
self.view.addSubview(webView)
self.navigationController?.isNavigationBarHidden = true
webView.backgroundColor = UIColor.clear
webView.scrollView.isScrollEnabled = false
webView.scrollView.bounces = false
}你使用它的self.navigationController?.isNavigationBarHidden = true,但导航栏没有隐藏。您是否实现了自定义导航栏和隐藏本机栏?或者它不一定是可见的?
https://stackoverflow.com/questions/57970557
复制相似问题