我使用UISlider在几分钟内(范围1 - 120)获取倒数计时器的输入,并将其显示在类似“01:30:00”的标签上。 i)我希望当用户设置计时器(使用滑块)来调整小时和分钟而不是秒。在用户开始倒计时后,秒数应开始计时。我怎样才能做到这一点? ii)我无法更新倒计时标签。有人可以建议正确的代码吗?
-(IBAction)setTime:(id)sender {
totaltime=timeSlider.value;
hours = totaltime / 60;
minutes = (totaltime % 3600) % 60;
seconds = (totaltime % 3600) * 60;
[countDownLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:45]];
countDownLabel.text = [NSString stringWithFormat:@"%.2i:%.2i:%.2i", hours, minutes, seconds]; }
-(void)countdown {
totaltime -=1;
if(minutes == 0) { [timer invalidate]; }
[countDownLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:45]];
countDownLabel.text = [NSString stringWithFormat:@"%.2i:%.2i:%.2i", hours, minutes, seconds]; }
-(IBAction)fade {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector (countdown) userInfo:nil repeats:YES]; }
答案 0 :(得分:3)
-(IBAction)setTime:(id)sender {
totaltime=timeSlider.value;
hours = totaltime / 60;
minutes = (totaltime % 3600) % 60;
seconds = (totaltime % 3600) * 60;
[countDownLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:45]];
countDownLabel.text = [NSString stringWithFormat:@"%.2i:%.2i:%.2i", hours, minutes, seconds]; }
-(void)countdown {
totaltime -=1;
totaltime=timeSlider.value;
hours = totaltime / 60;
minutes = (totaltime % 3600) % 60;
seconds = (totaltime % 3600) * 60;
countDownLabel.text = [NSString stringWithFormat:@"%.2i:%.2i:%.2i", hours, minutes, seconds];
if(minutes == 0) { [timer invalidate]; }
[countDownLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:45]];
countDownLabel.text = [NSString stringWithFormat:@"%.2i:%.2i:%.2i", hours, minutes, seconds]; }
-(IBAction)fade {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector (countdown) userInfo:nil repeats:YES]; }
答案 1 :(得分:2)
您正在减少totalTime
,但不会重新计算您的小时,分钟和秒。所以我想当你开始倒计时时,什么都没有改变?您需要在countdown
方法中重新计算小时,分钟和秒。