倒数计时器的循环进度条/ PIE

时间:2014-05-11 05:06:27

标签: ios objective-c progress-bar countdown countdowntimer

我的应用程序中有一个15秒计时器需要在圆形进度条中添加动画,其中包含以秒为中心的标签

下面的代码给出了0.0到1.0f的labelprogress,但我想把它映射到15秒倒计时,如果有计时器扩展器,它还应该用平滑的动画添加时间,这是顺畅的动画

ex:首先我需要从15秒开始,如果用户点击timeextender上电,当前时间是10秒,那么它应该是25秒,并且相应的进度条百分比应该有效。

那么我需要绘制什么逻辑才能完成上述要求

- (void)progressChange
{

    // Labeled progress views
    NSArray *labeledProgressViews = @[//self.labeledProgressView,
                                      self.labeledLargeProgressView];
    for (DALabeledCircularProgressView *labeledProgressView in labeledProgressViews) {
        CGFloat progress = ![self.timer isValid] ? self.stepper.value / 10.0f : labeledProgressView.progress + 0.01f;
        [labeledProgressView setProgress:progress animated:YES];


        labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%.2f", labeledProgressView.progress];
    }


}


- (void)startAnimation
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.03
                                                  target:self
                                                selector:@selector(progressChange)
                                                userInfo:nil
                                                 repeats:YES];
    self.continuousSwitch.on = YES;
}

- (void)stopAnimation
{
    [self.timer invalidate];
    self.timer = nil;
    self.continuousSwitch.on = NO;
}

- (IBAction)TimeExtender:(id)sender
{
   if (labeledProgressView.progress >= 1.0f && [self.timer isValid]) {
           [labeledProgressView setProgress:0.f animated:YES];
        }
}

1 个答案:

答案 0 :(得分:1)

我自己在这里解决了代码

- (void)progressChange
{

    CGFloat progress ;
    DALabeledCircularProgressView *labeledProgressView = self.labeledLargeProgressView;
    if(labeledProgressView.progress >=1.0f && [self.timer isValid]){
        [self stopAnimation];
         seconds = 15.0f;
    }
    else{
        progress=labeledProgressView.progress + 0.06666667f;
        [labeledProgressView setProgress:progress animated:YES];
        seconds --;
        labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%i", seconds];
    }


}

- (void)startAnimation
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                  target:self
                                                selector:@selector(progressChange)
                                                userInfo:nil
                                                 repeats:YES];
    self.continuousSwitch.on = YES;
}