0

我正在使用 NSTimer 和循环进度条作为倒数计时器,即 15 秒

它使用以下代码,但我得到进度条的刻度动画而不是平滑动画,如何使其平滑动画

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

2 回答 2

1

我发现的是一组 UIview 动画和进度视图动画,它们工作得更好,并且可以平滑地动画进度视图。如果您只是使用动画和进度视图动画的组合,它会直接触发而不考虑 UIview 动画计时器。

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

随意调整动画时间以获得更好、更流畅的过渡

于 2014-06-27T09:26:01.763 回答
0

我自己解决了我所做的是我更频繁地更新 0.1f 而不是 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;
}
于 2014-05-11T08:43:59.020 回答