// ==============================================================
// hideShowProgressView
// ==============================================================
- (void)hideShowProgressView:(BOOL)inShow
{
CGRect newFrame;
CGRect windowframe = [[UIScreen mainScreen] bounds];
// The main screen frame is always the same so we need to go offscreen
// to a different place depending on the interface orientation
// If landscape the sizes will be backwards, origin is always 0, 0
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
CGFloat width = windowframe.size.width;
windowframe.size.width = windowframe.size.height;
windowframe.size.height = width;
}
CGRect offframe = windowframe;
offframe.origin.y += offframe.size.height + 10;
if (inShow)
{
// Build and show the progress view
UIView* backgroundView = [[UIView alloc] initWithFrame:offframe];
UIActivityIndicatorView* progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Center the activity indicator view in the backgroundView
CGRect progressFrame = progress.frame;
progress.frame = CGRectMake(offframe.size.width/2 - progressFrame.size.width/2, offframe.size.height/2 - progressFrame.size.height/2, progressFrame.size.width, progressFrame.size.height);
progress.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
[progress startAnimating];
backgroundView.alpha = 0.6f;
backgroundView.backgroundColor = [UIColor blueColor];
backgroundView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[backgroundView addSubview:progress];
self.progressView = backgroundView;
[progress release];
[backgroundView release];
// Add the progress view to the navigation controller view and it covers everything
// and also rotates correctly
[self.navigationController.view addSubview:backgroundView];
newFrame = windowframe;
}
else
{
// Hide the progress view
newFrame = offframe;
}
// Animate the view on or off the screen
// need to remove the view when the animation finishes
[UIView beginAnimations:@"animation1" context:NULL];
[UIView setAnimationDuration:0.3];
if (! inShow)
{
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
}
self.progressView.frame = newFrame;
[UIView commitAnimations];
}
// ==============================================================
// animationDidStop:finished:context:
// ==============================================================
-(void)animationDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void *)context
{
[self.progressView removeFromSuperview];
self.progressView = nil;
}
- (void)showProgressView
{
if (! self.progressView)
[self hideShowProgressView:YES];
}
- (void)hideProgressView
{
[self hideShowProgressView:NO];
}