Skip to content

Instantly share code, notes, and snippets.

@AtomicCat
Created July 19, 2011 20:24
Show Gist options
  • Select an option

  • Save AtomicCat/1093617 to your computer and use it in GitHub Desktop.

Select an option

Save AtomicCat/1093617 to your computer and use it in GitHub Desktop.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void)
{
// take snapshot of main view to fake background
//
// start with a vertical slice of the middle, slightly taller than modal
//
// translate & clip layer before rendering for performance
//
CGContextRef c = CGBitmapCreateSomethingSomething(args);
CGContextTranslateCTM(c, (baseView.bounds.size.width - 540) / -2, 0);
CGContextClipToRect(c, CGRectMake((baseView.bounds.size.width - 540) / 2, 0, 540, baseView.bounds.size.height - ((baseView.bounds.size.height - 620) / 2)));
// render to context
//
[baseView.layer renderInContext:UIGraphicsGetCurrentContext()];
CGImageRef imageRef = CGBitmapCreateImagePlease(c);
CGContextRelease(c);
// set image from it
//
dispatch_saync(dispatch_get_main_queue(), ^(void)
{
backgroundImageView.image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment