1)保存當前時間(您可以通過示例將其保存到NSUserDefaults)。 你可以做這樣的事情:
NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
NSDate *currentDate = [NSDate date];
[user1 setObject:[NSNumber numberWithDouble:[currentDate timeIntervalSince1970]] forKey:@"time"];
[user1 synchronize];
2)安排調用你的函數像你這樣做是
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(moreProgress)
userInfo:Nil repeats:YES];
3)接下來在你的工作,你需要更新的東西進度視圖狀態這樣的:
//selector progress time
- (void) moreProgress {
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
NSDate *startTime = [NSDate dateWithTimeIntervalSince1970:[[user objectForKey:@"time"]doubleValue]];
NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow];
float progress = (float)elapsed time/30.0 * 60.0;
myProgressView.progress = progress;
if ((float)elapsedTime/30 * 60 >= 1)
{
// The timer is end, you should stop it and do what you need
}
}
注: 這不是安全的期望
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(moreProgress)
將每秒啓動。它不能保證也不準確。
我不知道我理解你的問題。你的意思是你想讓progressView花費30分鐘才能變滿,對嗎? – 2014-11-03 14:58:13
是:)多數民衆贊成在我想要的 – Andy 2014-11-03 15:06:18