0
[UIView animateWithDuration:10000 animations:^{
    [self.RecomendedBar setProgress:self.whatProgressbarShouldBe animated:NO];
}];

很明显,我在一个动画块中设置了进度,我将其时间设置为 10k

然而它还是那么快。不到1秒。

事实上,如果我这样做:

    [self.RecomendedBar setProgress:self.whatProgressbarShouldBe animated:NO];
    [UIView animateWithDuration:10000 animations:^{

    }];

即使进度视图栏在动画块之外,它仍然以不到 1 秒的时间进行动画处理。

4

1 回答 1

2

一种方法是使用 NSTimer 生成用于更新进度条的时间间隔。例如,制作一个 15 秒长的进度条:

 NSTimer *progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.25f target:self selector:@selector(updateProgressBar) userInfo:nil repeats:YES];

 - (void)updateProgressBar {
     float newProgress = [self.progressBar progress] + 0.01666; // 1/60
     [self.progressBar setProgress:newProgress animated:YES];
 }

在标题中声明 updateProgressBar 方法。增量为 0.016666... 或 1/60,因为 0.25 秒的计时器间隔将在 15 秒内发生 60 次。

于 2013-12-11T04:50:03.407 回答