Skip to content

Instantly share code, notes, and snippets.

@blork
Created December 20, 2012 11:11
Show Gist options
  • Save blork/4344713 to your computer and use it in GitHub Desktop.
Save blork/4344713 to your computer and use it in GitHub Desktop.
Gmail Modal
//On presenting the modal...
UIImageView *backView = [[UIImageView alloc] initWithImage:[self.navigationController.view screenshot]];
[backView setTag:1338];
[self.navigationController.view addSubview:backView];
UIView *maskView = [[UIView alloc] initWithFrame:self.navigationController.view.frame];
[maskView setBackgroundColor:[UIColor blackColor]];
[maskView setTag:1337];
[self.navigationController.view addSubview:maskView];
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
// provides a perspective transform
CATransform3D layerTransform = CATransform3DIdentity;
layerTransform.m34 = 1.0 / -500;
// We then add the required rotation, in this case in the X axis
layerTransform = CATransform3DRotate(layerTransform, M_PI/18, 1.0f, 0.0f, 0.0f);
layerTransform = CATransform3DScale(layerTransform, 0.95, 0.95, 0.95);
// Then we apply the transformation to the layer
CALayer *layer = backView.layer;
layer.zPosition = 1000;
//Set the nav view way behind to avoid horrible clipping
self.navigationController.view.layer.zPosition = -1000;
//Setting shadowOpacity seems to force antialiasing...
layer.shadowOpacity = 0.01;
layer.transform = layerTransform;
} completion:nil];
// On viewDidAppear:
UIView *maskview = [self.navigationController.view viewWithTag:1337];
UIView *backview = [self.navigationController.view viewWithTag:1338];
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
//reset the transform
CALayer *layer = backview.layer;
layer.transform = CATransform3DIdentity;
} completion:^(BOOL complete){
//Move everything back into place
[maskview setAlpha:0.6];
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
[backview setAlpha:0];
} completion:^(BOOL complete){
[backview removeFromSuperview];
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
[maskview setAlpha:0];
} completion:^(BOOL complete){
[maskview removeFromSuperview];
}];
}];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment