Skip to content

Instantly share code, notes, and snippets.

@samleb
Created July 1, 2011 16:12
Show Gist options
  • Select an option

  • Save samleb/1058856 to your computer and use it in GitHub Desktop.

Select an option

Save samleb/1058856 to your computer and use it in GitHub Desktop.
+ (void)displaySpinnerOverlayOver:(UIView *)view {
UIActivityIndicatorView *spinner;
if (spinnerOverlayView == nil) {
spinnerOverlayView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
spinnerOverlayView.opaque = NO;
spinnerOverlayView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
spinnerOverlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;;
spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[spinnerOverlayView addSubview:spinner];
[spinner startAnimating];
[spinner release];
} else {
spinner = [spinnerOverlayView.subviews objectAtIndex:0];
}
spinner.center = CGPointMake(CGRectGetMidX(view.frame), CGRectGetMidY(view.frame));
[view addSubview:spinnerOverlayView];
spinnerOverlayView.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
spinnerOverlayView.alpha = 1.0;
[UIView commitAnimations];
}
+ (void)hideSpinnerOverlay {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(hideAnimationDidStop:finished:context:)];
spinnerOverlayView.alpha = 0.0;
[UIView commitAnimations];
[spinnerOverlayView removeFromSuperview];
}
+ (void)hideAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished {
[spinnerOverlayView removeFromSuperview];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment