SVProgressHUD在显示另一条消息后不显示

时间:2015-09-14 13:26:20

标签: ios swift svprogresshud

我试图用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")
        })
}

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

enter image description here

2 个答案:

答案 0 :(得分:2)

有两件事是错的,首先为什么要两次调度到同一个线程?第二,如果你想只是显示HUD不要忽略它。

using (var reader = new PdfReader("Source.Pdf")) { using (var fileStream = new FileStream("Dest.Pdf"), FileMode.Create, FileAccess.Write) { using (PdfStamper stamper = new PdfStamper(reader, fileStream)) { //Get a PdfContentByte object var cb = stamper.GetOverContent(reader.NumberOfPages); //Create a ColumnText object var ct = new ColumnText(cb); //Set the rectangle to write to ct.SetSimpleColumn(100, 30, 500, 90, 0, PdfContentByte.ALIGN_LEFT); //Add some text and make it blue so that it looks like a hyperlink var c = new Chunk("Click here!", linkFont); var congrats = new Paragraph("Congratulations on reading the eBook! "); congrats.Alignment = PdfContentByte.ALIGN_LEFT; c.SetAnchor("http://www.domain.com/pdf/response/" + encryptedId); //Add the chunk to the ColumnText congrats.Add(c); ct.AddElement(congrats); //Tell the system to process the above commands ct.Go(); } } } 会在一段时间后隐藏消息。你没有看到借调HUD的原因是因为它仍然删除了第一个。由于您只想更新,请不要调用解雇。

答案 1 :(得分: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()
            })
    }