After exploring several options, I decided to use UIProgressView (suggested by sudo in the comments) in combination with NSTimer, which updates progress ten times per second for ten seconds, I used this solution because:
- This is a standard item provided by apple.
- This option has no overhead for creating and uploading 100 images (as suggested by Krypton in the comments).
- In NSTimer, I can add a check to the updateProgressBar function to add some feedback to the user when the timer reaches a low level, i.e. vibration for the last three seconds, etc. (using animation, I donβt think I will have such an option).
Using the code below, suppose I have a UIProgressView variable named "progressView", an NSTimer named "timer" and a floating point variable named "time", and then:
-(void)updateProgressBar { if(time <= 0.0f) { //Invalidate timer when time reaches 0 [timer invalidate]; } else { time -= 0.01; progressView.progress = time; } } -(void)animateProgressView2 { progressView.progress = 1; time = 1; timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target: self selector: @selector(updateProgressBar) userInfo: nil repeats: YES]; }
Another way that I explored (seeing Disco comments), but decided not to use animation. In this case, I created two png-images called "redbar.png" and "greenbar.png", the idea forced them to be placed on top of each other (the green bar on the top / in the foreground) and for the duration of the animation the green bar is compressed, showing the red strip in the background.
UIImage *green= [UIImage imageNamed:@"greenbar.png"]; UIImage *red= [UIImage imageNamed:@"redbar.png"]; redBar.image = red;
An ideal solution would be to combine the UIProgressView and the UIAnimation block, but this is currently not an option (see this question to animate a change in the UIProgressView ).
Hope this helps someone in the future.
EDIT ::
It seems that the ideal solution that I mentioned above is now available in iOS5, taken from Apple's reference site:
setProgress: animated: Adjusts the current progress shown by the receiver, animating the change as necessary.
- (void) setProgress: (float) progress animated: (BOOL) animated
source share