zoukankan      html  css  js  c++  java
  • swift 加载网页 添加进度条

        /// 进度条:只在活动页展示
        fileprivate lazy var progressView:UIProgressView = UIProgressView()
        
        /// 进度条高度
        private var progressViewHeight:NSLayoutConstraint?
    
    
    //设置监听
      webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)
    
    //设置进度条高度约束
            progressViewHeight = progressView.heightAnchor.constraint(equalToConstant: 2)
            progressViewHeight?.isActive = true
    
                if #available(iOS 11.0, *) {
                    progressView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
                } else {
                    progressView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0).isActive = true
                }
    
    
    
    
    extension JYWebViewController: WKUIDelegate, WKNavigationDelegate,WKScriptMessageHandler {
    
        ///监听进度
        override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
            if (keyPath == "estimatedProgress") {
                progressView.progress = Float(self.webView.estimatedProgress)
            }
        }
        
        ///完成
        func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
            self.webLoadSuccess()
            progressViewHeight?.constant = 0
        }
    }
  • 相关阅读:
    剑指Offer对答如流系列
    剑指Offer对答如流系列
    KMP算法
    殊途同归
    从m个数中取top n
    用红黑树实现500万数据的动态排序
    返璞归真
    second blog编程之美------控制cpu曲线
    first blog编程之美-----计算1的个数
    mathematica入门学习记录:
  • 原文地址:https://www.cnblogs.com/qingzZ/p/11091265.html
Copyright © 2011-2022 走看看