Skip to content

Instantly share code, notes, and snippets.

@rd13
Created January 4, 2013 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rd13/4457820 to your computer and use it in GitHub Desktop.
Save rd13/4457820 to your computer and use it in GitHub Desktop.
Objective-C Xcode Decrementing Fluid Progress Bar
//.h
//IBOutlet UIProgressView *pv;
//.m
- (void)viewDidLoad
{
[super viewDidLoad];
pv.progress = 1.0;
[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
}
- (void)makeMyProgressBarMoving {
float actual = [pv progress];
if (actual > 0) {
//10 Seconds duration
pv.progress = actual - ((float)0.005);
//Update every 0.05 seconds to maintain fluidity.
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
} else {
//Progress bar has reached zero
}
}
/*
Timer interval calculation:
10 Seconds:
10 / 0.05 = 200
1 / 200 = 0.005
2 Seconds:
2 / 0.05 = 40
1 / 40 = 0.025
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment