本文介绍了NVActivityIndi​​catorView 仅用于特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个库 https://github.com/ninjaprox/NVActivityIndi​​catorView 来显示加载指示器.默认情况下,它会阻止整个视图控制器,但如何仅显示特定视图的活动指示器.例如,如果视图控制器包含一个 webview 和一些其他视图,则活动指示器应该仅用于 webview,我应该能够与其他视图交互.

I am using this library https://github.com/ninjaprox/NVActivityIndicatorView for showing the loading indicator. By default it blocks the entire view controller but how can I show the activity indicator only for the particular view. For example if a view controller contains a webview and some other view, the activity indicator should be only for the webview and I should be able interact with the other view.

class FaqViewController: UIViewController, UIWebViewDelegate
{

    @IBOutlet var faqWebView: UIWebView!
    static let activityData = ActivityData()
    var activityIndicator : NVActivityIndicatorView!

    override func viewDidLoad()
    {
        super.viewDidLoad()
        faqWebView.delegate = self
        faqWebView.loadRequest(URLRequest(url: URL(string: "https://www.google.com")!))
    }

    func webViewDidStartLoad(_ webView: UIWebView)
    {
        NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE = CGSize(width: 45, height: 45)
        NVActivityIndicatorPresenter.sharedInstance.startAnimating(FaqViewController.activityData)
    }

    func webViewDidFinishLoad(_ webView: UIWebView)
    {
        NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
    }
}

推荐答案

例如显示activityIndi​​cator

func webViewDidStartLoad(_ webView: UIWebView)
{
    //NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE = CGSize(width: 45, height: 45)
    //NVActivityIndicatorPresenter.sharedInstance.startAnimating(FaqViewController.activityData)

    let xAxis = self.view.center.x // or use (view.frame.size.width / 2) // or use (faqWebView.frame.size.width / 2)
    let yAxis = self.view.center.y // or use (view.frame.size.height / 2) // or use (faqWebView.frame.size.height / 2)



let frame = CGRect(x: (xAxis - 50), y: (yAxis - 50), width: 45, height: 45)
 activityIndicator = NVActivityIndicatorView(frame: frame)
activityIndicator.type = . ballScale // add your type
activityIndicator.color = UIColor.red // add your color

self.view.addSubview(activityIndicator) // or use  webView.addSubview(activityIndicator)
activityIndicator.startAnimating()
}

隐藏

func webView(_ webView: UIWebView, didFailLoadWithError error: Error)
    {
        hideactivityIndicator()
    }

   func webViewDidFinishLoad(webView: UIWebView!)
    {
      hideactivityIndicator()
    }

  func hideactivityIndicator()
  {

  activityIndicator. stopAnimating()
  activityIndicator.removeFromSuperview()
  }

这篇关于NVActivityIndi​​catorView 仅用于特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 19:44