0

I am using NSTimer and circular progress bar for the countdown timer i.e 15seconds

Its working with the following code but I am getting tick animation for the progress bar and not the smooth one, how to make it smooth animation

- (void)viewDidLoad
        {
            [super viewDidLoad];
           self.labeledLargeProgressView.roundedCorners = NO;
            self.labeledLargeProgressView.trackTintColor =[UIColor colorWithRed:0.0f/255.0f       green:173.0f/255.0f blue:255.0f/255.0f alpha:1.0f];
            self.labeledLargeProgressView.progressTintColor =[UIColor colorWithRed:255.0f/255.0f    green:96.0f/255.0f blue:88.0f/255.0f alpha:1.0f];
            self.labeledLargeProgressView.thicknessRatio = 1.0f;
            self.labeledLargeProgressView.clockwiseProgress = YES;
            [self.view addSubview:self.labeledLargeProgressView];
            seconds = 15.0;
            [self startAnimation];
        }

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

- (void)stopAnimation
{
    [self.timer invalidate];
    self.timer = nil;
    self.continuousSwitch.on = NO;
}
user1169079
  • 3,053
  • 5
  • 42
  • 71

2 Answers2

1

What i found out is a set of both UIview animations and progress view animatons that work much nicer and animate the progressview smoothly. If you just use the combination of animation and progressview animation it is fired directly without regard to the UIview animation timer.

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    timer = [NSTimer scheduledTimerWithTimeInterval: 1.0f
                                             target: self
                                           selector: @selector(updateTimer)
                                           userInfo: nil
                                            repeats: YES];
}


- (void)updateTimer
{
    if (progressView.progress >= 1.0) {
        [timer invalidate];
    }
    [UIView animateWithDuration:1 animations:^{
        float newProgress = [self.progressView progress] + 0.125;
        [self.progressView setProgress:newProgress animated:YES];
    }];
}

Feel free to adjust the animation times to even better and smooth transitions

EmilDo
  • 1,177
  • 3
  • 16
  • 33
0

I solved it by myself what I did is I am updating more frequently 0.1f instead of 1.0f

- (void)progressChange
{

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


}


- (void)startAnimation
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1
                                                  target:self
                                                selector:@selector(progressChange)
                                                userInfo:nil
                                                 repeats:YES];
    self.continuousSwitch.on = YES;
}
user1169079
  • 3,053
  • 5
  • 42
  • 71
  • You probably should have deleted your question; I doubt this answer will help anyone. – trojanfoe May 11 '14 at 08:55
  • 2
    If you are animating every 0.1 seconds, your animation is likely to still not be very smooth. You can use a CADisplayLink to get a callback every time the screen updates (usually about 60 Hz). – Zev Eisenberg May 11 '14 at 14:50