簡體   English   中英

取消視圖前,暫停應用以顯示消息一秒鍾

[英]Pausing app to display message for one second before dismissing a view

我有一個簡單的計時器,該計時器在完成時顯示消息“ Rest Time Complete”(Rest Time Complete),我希望該消息在屏幕上停留一秒鍾,然后關閉視圖。 我已經嘗試了一些我將在下面詳細介紹的事情,但是我永遠無法使該消息顯示,暫停然后關閉該視圖。 計時器停在計時器中的最后一個數字上,然后在關閉視圖時始終顯示該消息。 這是我的代碼:

- (void)restTimerComplete
{
    self.restTimeLabel.text = @"Rest Period Complete!";
    [NSThread sleepForTimeInterval:1];
    [self hideRestTimerAnimated:YES];
}

我也嘗試過使用簡單的sleep(1) ,但最終結果相同。

最簡單的方法是使用dispatch_after

- (void)restTimerComplete {
    self.restTimeLabel.text = @"Rest Period Complete!";
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self hideRestTimerAnimated:YES];
    });

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM