[英]Countdown Timer starts from 4 to 1
當我開始玩測驗時,計時器開始倒數“ 4…3…2…1…”。 我想在測驗的第一個問題中添加此倒數計時。 倒數后顯示第一個問題。
有人可以幫我嗎
我正在嘗試執行此操作,但我沒有獲取倒數格式。
NSTimer *timer_total = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
- (void)updateTimer
{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate_total];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
self.df_total = [[NSDateFormatter alloc] init];
[self.df_total setDateFormat:@"mm:ss"];
[self.df_total setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[self.df_total stringFromDate:timerDate];
self.lbl_total_Timer.text = timeString;
}
你可以喜歡
int currentTime;
- (IBAction)start{
currentTime = 5;
lbl=[[UILabel alloc]init];
//creates and fires timer every second
myTimer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showTime) userInfo:nil repeats:YES]retain];
}
-(void)showTime{
if(currentTime==0)
{
[myTimer invalidate];
myTimer = nil;
}
else{
currentTime--;
lbl.text = [NSString stringWithFormat:@"%.2d", currentTime];
}
NSLog(@"my lable == %@",lbl.text);
}
- (void)viewWillAppear:(BOOL)animated
{
[self start];
[super viewWillAppear:YES];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.