【问题标题】:How to make animation move slower on progress bar如何使动画在进度条上移动得更慢
【发布时间】:2013-12-11 04:35:35
【问题描述】:
[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 秒的时间进行动画处理。

【问题讨论】:

  • progress 属性不可设置动画。
  • UIProgressView 可以很好地反映变量随时间更新的变化,例如大型网络操作或长时间运行的计算。然而,UIProgressView 不是时钟,它不能很好地跟踪实际上没有变化的变量。如果你绝对需要强制 UIProgressView 只测量时间,David 的解决方案当然是合理的。

标签: objective-c uiprogressview uiprogressbar


【解决方案1】:

一种方法是使用 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 次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    相关资源
    最近更新 更多