我有一個倒數計時器,顯示音軌上剩餘的秒數。由於某些原因,倒計時不會以1秒的間隔計算,但第一次計數爲2秒,下一次計數則爲1秒。 (它在這種模式下計算 - 它跳過2秒,然後是1遍)。AVAudioPlayer - 在UILabel上顯示倒數計時器
這裏是我的代碼:
// display current time left on the track
- (void)updateTimeLeft {
NSTimeInterval timeLeft = self.player.duration - self.player.currentTime;
// update your UI with timeLeft
self.timeDisplay.text = [NSString stringWithFormat:@"%.2f", timeLeft/60];
}
,這裏是我的NSTimer:
NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimeLeft) userInfo:nil repeats:YES];
感謝您的幫助。
謝謝。我得到一個無效操作數對二進制模數%。我讀過%運算符不適用於浮點值。 – hanumanDev 2011-05-19 12:05:58
概念除以60分鐘並以60爲單位模數 – 2011-05-19 12:08:08
這就是我最終使用的模數運算。 \t \t int sec = lroundf(timeLeft)%60; – hanumanDev 2011-05-19 13:30:26