1

我正在尝试使用 SVProgressHUD 显示一个微调器,当我从服务器获得异步响应时,关闭该 hud 并显示另一个带有从服务器接收到的消息的 hud。

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    SVProgressHUD.setDefaultStyle(.Custom)
    SVProgressHUD.setForegroundColor(UIColor.whiteColor())
    SVProgressHUD.setBackgroundColor(UIColor.clearColor())
    SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.Clear)
    SVProgressHUD.show()
    loadData()

}

private func loadData() {
    ApiService.getData { (succeed, message) -> () in
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.dismissHud()
        })
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            SVProgressHUD.showInfoWithStatus("I can't see this")
        })
}

如果我删除 viewDidAppear 中显示 HUD 的代码,我可以看到该消息。有任何想法吗?谢谢

在此处输入图像描述

4

2 回答 2

2

有两件事是错误的,首先为什么要分派到同一个线程两次?其次,如果您只想显示 HUD,请不要关闭它。

SVProgressHUD.showInfoWithStatus一段时间后将隐藏消息。
您没有看到第二个 HUD 的原因是它仍然删除了第一个。由于您只想更新,请不要调用解雇。

于 2015-09-14T13:37:45.517 回答
0

我有更改FadeInAnimationDurationFadeoutAnimationDuration更改,0.0对我来说效果很好。我正在使用这样的HUD:

显示 HUD:

func showActivityLoader() {

            dispatch_async(dispatch_get_main_queue(), {

            SVProgressHUD.setFadeInAnimationDuration(0.0)
            SVProgressHUD.setFadeOutAnimationDuration(0.0)
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.Clear)
            SVProgressHUD.show()

            })
    }

隐藏 HUD:

func dismissActivityLoader() {

            dispatch_async(dispatch_get_main_queue(), { 

                SVProgressHUD.dismiss()
            })
    }
于 2016-08-24T14:46:12.027 回答