Skip to content

Commit

Permalink
Merge branch 'master' of github.com:michaelochs/BCBlurView
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ochs committed Jun 5, 2013
2 parents 7642a04 + 5f3f3af commit a529c30
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions BCBlurView/UIView+BCBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ - (void)drawBluredBackground:(CGFloat)blurRadius inRect:(CGRect)rect
// render the background we want to blur
self.hidden = YES; // make the button itself invisible as it should not be rendered!

CGRect windowRect = [self.window convertRect:rect fromView:self];
// walk up the view hierarchy to find the first view that is opaque
UIView* viewToRender = self.superview;
while (!viewToRender.opaque) {
if (viewToRender.superview) {
viewToRender = viewToRender.superview;
} else {
break; // maybe the window isn't set opaque!
}
}

CGRect renderRect = [viewToRender convertRect:rect fromView:self];

UIGraphicsBeginImageContext(rect.size);

CGContextTranslateCTM(UIGraphicsGetCurrentContext(), -CGRectGetMinX(windowRect), CGRectGetMaxY(windowRect));
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), -CGRectGetMinX(renderRect), CGRectGetMaxY(renderRect));
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0f, -1.0f);

[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
[viewToRender.layer renderInContext:UIGraphicsGetCurrentContext()];

CGImageRef blurInputReference = [UIGraphicsGetImageFromCurrentImageContext() CGImage];

Expand Down

0 comments on commit a529c30

Please sign in to comment.