2017-09-15 8 views
1

J'utilise cette bibliothèque https://github.com/ninjaprox/NVActivityIndicatorView pour afficher l'indicateur de chargement. Par défaut, il bloque tout le contrôleur de vue, mais comment puis-je afficher l'indicateur d'activité uniquement pour la vue en question. Par exemple, si un contrôleur de vue contient une vue Web et une autre vue, l'indicateur d'activité doit être uniquement pour la vue Web et je devrais pouvoir interagir avec l'autre vue.NVActivityIndicatorAfficher uniquement pour une vue particulière

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

ce qui est votre 'cadre UIWebView' –

+0

Comme cela remplit maintenant toute la vue. Mais je veux interagir avec le contrôleur de navigation à tout moment pour revenir en arrière même lorsque la page est en cours de chargement. –

+0

modifiez le cadre de votre 'NVActivityIndicatorView' en utilisant' let x = self.view.center.x let y = self.view.center.y laissez frame = CGRect (x: (x - 50), y: (y - 50), largeur: 100, hauteur: 100) NVActivityIndicatorView (cadre: frame) ' –

Répondre

2

pour le montrer par exemple 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() 
} 

pour cacher

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

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

    func hideactivityIndicator() 
    { 

    activityIndicator. stopAnimating() 
    activityIndicator.removeFromSuperview() 
    } 
+0

en l'ajoutant comme une sous-vue a fait l'affaire pour moi .. –

+0

j'ai essayé la même chose pour l'image mais il n'a pas fonctionné? Puis-je savoir quel serait le problème? L'imageview est une sous-vue d'une vue. –

+0

imageview signifie –