【发布时间】:2017-09-17 11:37:35
【问题描述】:
我无法从我的应用委托中的某个函数停止活动指示器,我知道该函数正在被调用,但我的日志中没有收到任何错误。
我正在像这样在我的 signInViewController 中创建 activityIndicator
@IBAction func googleSignInButton(_ sender: Any) {
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signIn()
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.white
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.shared.beginIgnoringInteractionEvents()
}
在我的应用委托之后,我有了这个功能,
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
print("this function is running")
SignInViewController().stopanimating()
// ...
if error != nil {
// ...
return
}
我知道这个功能可以正常工作,因为它会在日志等中打印文本。并从 SignInViewController 调用此函数
func stopanimating() {
print("stop animating function running")
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
}
}
现在我知道此函数正在运行,因为它还会在日志中打印预期的文本,并且 endIgnoringInteractionEvents 确实有效,但活动指示器仍在运行
我对 swift 很陌生,但之前从我的 appdelegate 操作视图控制器中的对象时遇到问题,这可能吗?
提前致谢
【问题讨论】:
-
首先确保执行顺序是 current 。如果您尝试以异步方式从您的应用委托委托中禁用动画。它可能会在开始动画之前被调用。其次,我可能是错的,但看起来您在尝试禁用动画时使用的是类而不是视图控制器的实例。是故意的吗?
标签: ios swift appdelegate uiactivityindicatorview