【问题标题】:WKWebview not fully loaded in iOS 10.3WKWebview 未在 iOS 10.3 中完全加载
【发布时间】:2018-03-15 08:53:38
【问题描述】:

我遇到了在 WKWebview 中加载本地 html 文件的问题。 我的程序适用于 iOS 8、9、11,但不适用于 10.3。文本中间只有一个空格。

我正在像这样创建我的 WKWebview:

let webConfiguration = WKWebViewConfiguration();
let frame = CGRect(x: 0, y: 0, width: cell.frame.width, height: self.webViewHeight);
infoWebView = WKWebView(frame: frame, configuration: webConfiguration);
infoWebView.navigationDelegate = self;
infoWebView.translatesAutoresizingMaskIntoConstraints = false
infoWebView.scrollView.isScrollEnabled = false;
infoWebView.clipsToBounds = false;
infoWebView.allowsBackForwardNavigationGestures = false
infoWebView.contentMode = .scaleToFill
infoWebView.sizeToFit()

我的html文件的加载是通过以下代码完成的:

if let availableUrl = url {
                let urlRequest = URLRequest(url: availableUrl)
                infoWebView.load(urlRequest)
            }

您知道为什么它适用于 iOS 8、9、11 但不适用于 iOS 10.3? 有人能重现这个问题吗?

问候,祝你有美好的一天!

【问题讨论】:

    标签: ios swift uiwebview ios10 wkwebview


    【解决方案1】:

    由于我的 wkwebview 在表格视图中,我不得不从 UITableViewDelegate 覆盖 scrollViewDidScroll。

    WKWebView not rendering correctly in iOS 10 的这段代码对我有用:

    // in the UITableViewDelegate
    func scrollViewDidScroll(scrollView: UIScrollView) {
        if let tableView = scrollView as? UITableView {
            for cell in tableView.visibleCells {
                guard let cell = cell as? MyCustomCellClass else { continue }
                cell.webView?.setNeedsLayout()
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 2019-10-11
      • 1970-01-01
      • 2023-03-13
      相关资源
      最近更新 更多