Skip to content

Instantly share code, notes, and snippets.

@jpsim
Last active December 25, 2015 20:39
Show Gist options
  • Save jpsim/7036492 to your computer and use it in GitHub Desktop.
Save jpsim/7036492 to your computer and use it in GitHub Desktop.
UIProgressView Always Animates
UIProgressView *v = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
v.frame = CGRectMake(40, 100, 240, 2);
[self.view addSubview:v];
{
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[v setProgress:0.5f animated:NO];
});
}
{
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[v setProgress:0.75f animated:NO];
});
}
{
double delayInSeconds = 3.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[v setProgress:1.0f animated:NO];
});
}
@jpsim
Copy link
Author

jpsim commented Oct 18, 2013

Why does UIProgressView's setProgress:Animated: method always animate the change?

@stevebrambilla
Copy link

Not sure why, but I have had similar issues with other controls in iOS 7. As a workaround, I found that disabling animations altogether when updating the value and laying out the views takes care of it:

[UIView performWithoutAnimation:^{
    [v setProgress:1.0f animated:NO];
    [v layoutIfNeeded];
}];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment