Skip to content

Commit

Permalink
Adds support for UITableViewController and UICollectionViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroFranco committed Jun 8, 2014
1 parent 06c144e commit 3590989
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 22 deletions.
44 changes: 33 additions & 11 deletions Classes/AFBlurSegue.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,27 @@ -(void)perform {
UIViewController *sourceController = self.sourceViewController;
UIViewController *destinationController = self.destinationViewController;

UIGraphicsBeginImageContextWithOptions(sourceController.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[sourceController.view.layer renderInContext:context];
UIImage *background = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *background = [UIImage new];

if ([sourceController isKindOfClass:[UITableViewController class]]) {

UIView *viewToRender = [(UITableViewController *)sourceController tableView];
CGPoint contentOffset = [[(UITableViewController *)sourceController tableView]contentOffset];

UIGraphicsBeginImageContext(viewToRender.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, -contentOffset.y);
[viewToRender.layer renderInContext:context];
background = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
} else {

UIGraphicsBeginImageContextWithOptions(sourceController.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[sourceController.view.layer renderInContext:context];
background = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

switch ([[UIApplication sharedApplication]statusBarOrientation]) {
case UIInterfaceOrientationPortrait:
Expand All @@ -43,15 +59,15 @@ -(void)perform {
case UIInterfaceOrientationPortraitUpsideDown:
background = [UIImage imageWithCGImage:background.CGImage scale:1 orientation:UIImageOrientationDown];
break;

case UIInterfaceOrientationLandscapeLeft:
background = [UIImage imageWithCGImage:background.CGImage scale:1 orientation:UIImageOrientationLeft];
break;

case UIInterfaceOrientationLandscapeRight:
background = [UIImage imageWithCGImage:background.CGImage scale:1 orientation:UIImageOrientationRight];
break;

default:
break;
}
Expand All @@ -65,10 +81,16 @@ -(void)perform {
} else {
blurredBackground.frame = CGRectMake(0, 0, backgroundRect.size.width, backgroundRect.size.height);
}



destinationController.view.backgroundColor = [UIColor clearColor];
[destinationController.view addSubview:blurredBackground];
[destinationController.view sendSubviewToBack:blurredBackground];

if ([destinationController isKindOfClass:[UITableViewController class]]) {
[[(UITableViewController *)destinationController tableView]setBackgroundView:blurredBackground];
} else {
[destinationController.view addSubview:blurredBackground];
[destinationController.view sendSubviewToBack:blurredBackground];
}

[sourceController presentViewController:destinationController animated:YES completion:nil];

Expand All @@ -80,4 +102,4 @@ -(void)perform {
} completion:nil];
}

@end
@end
44 changes: 33 additions & 11 deletions Demo/AFBlurSegue-Demo/AFBlurSegue.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,27 @@ -(void)perform {
UIViewController *sourceController = self.sourceViewController;
UIViewController *destinationController = self.destinationViewController;

UIGraphicsBeginImageContextWithOptions(sourceController.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[sourceController.view.layer renderInContext:context];
UIImage *background = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *background = [UIImage new];

if ([sourceController isKindOfClass:[UITableViewController class]]) {

UIView *viewToRender = [(UITableViewController *)sourceController tableView];
CGPoint contentOffset = [[(UITableViewController *)sourceController tableView]contentOffset];

UIGraphicsBeginImageContext(viewToRender.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, -contentOffset.y);
[viewToRender.layer renderInContext:context];
background = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
} else {

UIGraphicsBeginImageContextWithOptions(sourceController.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[sourceController.view.layer renderInContext:context];
background = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

switch ([[UIApplication sharedApplication]statusBarOrientation]) {
case UIInterfaceOrientationPortrait:
Expand All @@ -43,15 +59,15 @@ -(void)perform {
case UIInterfaceOrientationPortraitUpsideDown:
background = [UIImage imageWithCGImage:background.CGImage scale:1 orientation:UIImageOrientationDown];
break;

case UIInterfaceOrientationLandscapeLeft:
background = [UIImage imageWithCGImage:background.CGImage scale:1 orientation:UIImageOrientationLeft];
break;

case UIInterfaceOrientationLandscapeRight:
background = [UIImage imageWithCGImage:background.CGImage scale:1 orientation:UIImageOrientationRight];
break;

default:
break;
}
Expand All @@ -65,10 +81,16 @@ -(void)perform {
} else {
blurredBackground.frame = CGRectMake(0, 0, backgroundRect.size.width, backgroundRect.size.height);
}



destinationController.view.backgroundColor = [UIColor clearColor];
[destinationController.view addSubview:blurredBackground];
[destinationController.view sendSubviewToBack:blurredBackground];

if ([destinationController isKindOfClass:[UITableViewController class]]) {
[[(UITableViewController *)destinationController tableView]setBackgroundView:blurredBackground];
} else {
[destinationController.view addSubview:blurredBackground];
[destinationController.view sendSubviewToBack:blurredBackground];
}

[sourceController presentViewController:destinationController animated:YES completion:nil];

Expand All @@ -80,4 +102,4 @@ -(void)perform {
} completion:nil];
}

@end
@end

0 comments on commit 3590989

Please sign in to comment.