Created
January 4, 2013 22:11
-
-
Save rd13/4457820 to your computer and use it in GitHub Desktop.
Objective-C Xcode Decrementing Fluid Progress Bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//.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