2013-12-11 31 views
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秒动画甚至认为progressview酒吧外面动画块。

+0

“进度”属性不具动画性。 – rmaddy

+0

UIProgressView在反映随时间变化的变量方面做得非常出色,例如大型网络操作或长时间运行的计算。然而,UIProgressView不是一个时钟,并且它不会很好地跟踪实际上并未改变的变量。 如果你绝对需要强制UIProgressView来测量除时间之外的任何东西,David的解决方案当然是合理的。 –

回答

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次。