2017-08-06 54 views
1

在我的SignInViewController中,我有这个代码,当点击一个按钮并在我的应用程序委托中添加活动时,当功能完成时我运行stopanimating函数,我知道该函数正在运行把它打印出来的东西,但活动指示灯不dissapearingUIActivityIndi​​cator stopAnimating()不起作用

非常appriciated很新的快捷所以简单化的答案任何帮助赞赏

 @IBAction func googleSignInButton(_ sender: Any) { 

      GIDSignIn.sharedInstance().uiDelegate = self 
      GIDSignIn.sharedInstance().signIn() 


      activityIndicator.center = self.view.center 
      activityIndicator.hidesWhenStopped = true 
      activityIndicator.activityIndicatorViewStyle = 
      UIActivityIndicatorViewStyle.gray 
      view.addSubview(activityIndicator) 

      activityIndicator.startAnimating() 
      UIApplication.shared.beginIgnoringInteractionEvents() 


     } 

     func stopanimating() { 
     activityIndicator.stopAnimating() 
     UIApplication.shared.endIgnoringInteractionEvents() 
     } 
+0

你在主线程中调用'stopanimating()'吗? – Bilal

+0

即时通讯线程不知道你的意思,你的意思是在当前的视图控制器,如果没有即时通过调用var sivc = SignInViewController(),然后func(){...在应用程序委托在函数结束调用它。 .. sivc.stopanimating} – Ray

+0

@Ray是你的函数被调用。 –

回答

2

尝试在主线程中调用stopanimating()

func stopanimating() { 
    DispatchQueue.main.async { 
     self.activityIndicator.stopAnimating() 
    } 
} 
+0

它需要我把self.activityIndi​​cator.stopAnimating(),但仍然没有摆脱活动指标 – Ray

+2

不是你最初的问题,而是你对“自我”的评论fyi:它需要你把“self.activityIndi​​cator。 ..“,因为Swift希望你理解,只要你在闭包{...}中引用该变量,就可能导致引用循环。 – Alienbash

+0

你有从你的“activityIndi​​cator”到你的SignInViewController()类的插座吗?它在您上面发布的代码中不可见,所以您可能只是实例化一个类型为ActivityIndi​​cator的新对象。 – Alienbash

相关问题