It seems like a pretty simple problem, but I have been unable to find any good answers.
What I\'m trying to do is to make some sort of animation while some function is l
I guess it depends on what is being loaded? Are you waiting for a response from a server? In that case I usually put a spinning wheel (UIActivityIndicatorView) on my view that has the hide when not animating checkbox checked (there is a message to set this programmatically as well). Then when the data is received from the server I simply call stopAnimating on the UIActivityIndicator view and it will hide. You can then show whatever it is you need to show.
Ah-ha! I've just stumbled upon a most handy class: MBProgressHUD. Give it a try. I do believe it does what you seek, and then some.
I've also contributed a few mods in the author's blog post comments.
You need to implement a new thread for the work that needs to be done between the start and the stop of the animation.
See following:
http://discussions.apple.com/thread.jspa?threadID=1531358&start=0&tstart=0
On an aesthetic note, notice that UIActivityIndicatorView
comes with several built-in styles for you to choose from. The code examples above use the Gray and White options, but there are several more described in Apple's documentation. You can set the style by using:
-initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyle)
or by setting the object's activityViewIndicatorStyle
property.
Your issue will be that the activity indicator will not be displayed because it will only be shown on the next pass through the run loop - by which time you will have done everything you need to!
The very very very easiest way of doing this is to move your code to call the next view into its own method then (having built a UIActivityIndicator as per other posts here) do
[self.myactivityindicator startAnimating];
[self performSelector:@selector(myCodeToCallTheView) withObject:nil afterDelay:0];
this gives just enough of a chance for the indicator to be drawn before running your code to draw the view. Of course once your new view appears it will overwrite the selector.
you can add an UIActivityIndicatorView as a subview to a view and when the action is over you can remove it from superview...
UIActivityIndicatorView *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
av.frame=CGRectMake(145, 160, 25, 25);
av.tag = 1;
[yourView addSubview:av];
[av startAnimating];
removing it
UIActivityIndicatorView *tmpimg = (UIActivityIndicatorView *)[yourView viewWithTag:1];
[tmpimg removeFromSuperview];
hope it helps...