我是新来的iPhone NSTimer。我做了一个秒表。现在我想暂停 之间的时间,也想恢复暂停。我的代码给出在下面。暂停在iPhone中停止计时计时器?
- 我该如何暂停时间?
- 我该如何从时间停止的地方恢复?
开始时间:
startDate = [[NSDate date]retain];
stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
停产时间:
[stopWatchTimer invalidate];
stopWatchTimer = nil;
[self updateTimer];
更新时间:
(void)updateTimer
{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[dateFormatter stringFromDate:timerDate];
stopWatchLabel.text = timeString;
[dateFormatter release];
}
我知道的NSTimer没有暂停和恢复方法。但我不知道如何暂停,所以有什么逻辑来暂停计时器。顺便谢谢你的夸奖。 – Rishabh
那么你为什么说“我是NSTimer的新手,我做了一个秒表,现在我想暂停时间,也想暂停恢复”。 :) – Gabe
但我想在我的程序加入暂停按钮等等...... – Rishabh