Iphone – How to display a progress indicator overlay/HUD on iPhone

cocoa-touchcore-animationiphone

I want to display a progress indicator in a semi-transparent box that floats over a table view. In other words, when the table contents are being downloaded, I want an "Updating" label to appear over it.

I have seen this in several apps in the store, notably Facebook (when you shake to reload) and Darkslide.

My first impulse is to create a semi-transparent UIView, place a UILabel and a UIProgressIndicatorView inside it, and add it to the view hierarchy… but where? A UIView may not overlap its siblings, so I can't make it a subview of the window. I also can't make it a subview of the table, because then it will scroll up and down with the table content.

I thought about creating a new UIWindow, but the documentation basically says don't.

I know CALayers can overlap each other, so that would be an option, but I can't put a progress indicator inside a CALayer, can I? Should I roll my own progress indicator that animates a CALayer instead of a UIView?

I'm not interested in hearing about private APIs.

Edit: The question was based on a faulty assumption. NSViews (on Mac OS X) may not overlap, but UIViews on the iPhone may.

Best Answer

I've just posted a HUD version of mine : https://github.com/y0n3l/LGViewHUD

you can get this result very easily :

#import "LGViewHUD.h"
.... 
LGViewHUD* hud = [LGViewHUD defaultHUD];
hud.activityIndicatorOn=YES;
hud.topText=@"The longer....";
hud.bottomText=@"The better !";
[hud showInView:self.view];

enter image description here

Once the task is ended, just invoke

[[LGViewHUD defaultHUD] hideWithAnimation:HUDAnimationHideFadeOut];

and that's it !