简体   繁体   English

NVActivityIndi​​catorView仅适用于特定视图

[英]NVActivityIndicatorView only for particular view

I am using this library https://github.com/ninjaprox/NVActivityIndicatorView for showing the loading indicator. 我正在使用此库https://github.com/ninjaprox/NVActivityIndi​​catorView来显示加载指示器。 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. 例如,如果视图控制器包含webview和其他视图,则活动指示符应仅用于webview,并且我应该能够与其他视图交互。

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()
    }
}

for eg show the activityIndicator 例如,显示activityIndicator

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()
}

for hide 为了隐藏

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

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

  func hideactivityIndicator()
  {

  activityIndicator. stopAnimating()
  activityIndicator.removeFromSuperview()
  }

You have to add it as a subView for the what ever the view you want to show it on. 您必须将其添加为子视图,以便显示要显示的视图。 In you case you want to show only on UIWebView, then your code should look like 在您的情况下,您只想在UIWebView上显示,那么您的代码应该是这样的

self.faqWebView.addSubView(activityIndicator)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM