我想要一個UIProgressView並將其與NSTimer(20s)連接起來,並且可以讓計時器順利進行「倒計時」進度條。似乎我在這方面找到的信息與我並不完全一致。向後進度條(倒計時)
誰能告訴我如何做到這一點?
我想要一個UIProgressView並將其與NSTimer(20s)連接起來,並且可以讓計時器順利進行「倒計時」進度條。似乎我在這方面找到的信息與我並不完全一致。向後進度條(倒計時)
誰能告訴我如何做到這一點?
讓您的NSTimer調用一個函數,用
#define TIMER_INTERVAL 0.05f
[NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL
target:self
selector:@selector(timerMethod:)
userInfo: [NSNumber numberWithFloat:1.0f]
repeats:YES];
,然後在功能,更新UIProgressView基礎上的NSTimer的用戶信息屬性,像這樣:
-(void) timerMethod: (NSTimer *)timer
{
float progress = timer.userInfo.floatValue;
[progressView setProgress:progress animated:YES];
if (progress <= 0.0f)
[timer invalidate];
else
timer.userInfo = [NSNumber numberWithFloat:(progress - (1.0f/20.0f)*TIMER_INTERVAL)];
}
單身男人或只是拼寫錯誤? ('.Invalidate();'和'NumberWithFloat:'和'if(float <= 0.0f)') –
錯別字。對。只是錯別字。 –
@PatLillis _謝謝你!! _ – Maegan
哪一部分可以」你知道嗎?讓它倒退?計時器如何工作? –
是的,我試過將兩個鏈接連接失敗。我知道一個計時器是如何工作的,但我對進度觀點很陌生,所以我不知道如何讓它倒退或前進。 – Maegan
您不應該使用進度條進行倒計時等操作。這是一個_progress欄_不是「倒計時欄」。用戶在倒退時可能會感到困惑。 – CouchDeveloper