user1169079
user1169079

Reputation: 3083

Circular Progress bar / PIE for countdown timer

I have a requirment of 15sec timer in my app in the circular progress bar sort of animation which will contain label in the center of seconds remain

Following code gives the labelprogress from 0.0 to 1.0f but I want to map it to 15 seconds countdown with the smooth animation also if there is timer extender than it should get the time added with the smooth animation

ex: Firstly I need to start from 15 seconds and if user clicks on the timeextender powerup and current time is the 10sec then it should be 25 sec and acoordingly the progressbar percentage should work.

So what logic I need to map to get the above requirement done

- (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];
        }
}

Upvotes: 1

Views: 1180

Answers (1)

user1169079
user1169079

Reputation: 3083

I solved it by myself here's the code

- (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;
}

Upvotes: 1

Related Questions