Skip to content

Instantly share code, notes, and snippets.

@jparishy
Created August 9, 2011 21:03
Show Gist options
  • Save jparishy/1135185 to your computer and use it in GitHub Desktop.
Save jparishy/1135185 to your computer and use it in GitHub Desktop.
Opening the view
-(void)openEditAnimationFromCellRect:(CGRect)rect withView:(UIView *)underView
{
[self.tableView setScrollsToTop:NO];
[self.tableView setScrollEnabled:NO];
originalOffset = self.tableView.contentOffset;
targetOffset = CGPointMake(0.0f, rect.origin.y);
[UIView animateWithDuration:0.5f animations:^(void) {
self.tableView.contentOffset = targetOffset;
}
completion:^(BOOL finished)
{
// Get a UIImage of the contents of the view as they are now
float scale = [[UIScreen mainScreen] scale];
UIGraphicsBeginImageContextWithOptions(self.view.superview.frame.size, true, scale);
CGContextRef imageContext = UIGraphicsGetCurrentContext();
[self.view.superview.layer renderInContext:imageContext];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
float containerY = rect.size.height;
openingContainer = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, self.view.frame.size.height)];
[openingContainer setBackgroundColor:[UIColor purpleColor]];
UIView* topView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, containerY)];
[topView addSubview:[[[UIImageView alloc] initWithImage:image] autorelease]];
[topView setClipsToBounds:YES];
openingBottomImage = [[UIView alloc] initWithFrame:CGRectMake(0.0f, containerY, 320.0f, self.view.frame.size.height - containerY)];
[openingBottomImage addSubview:[[[UIImageView alloc] initWithImage:image] autorelease]];
CGRect bottomBounds = openingBottomImage.bounds;
bottomBounds.origin.y += containerY;
[openingBottomImage setBounds:bottomBounds];
[openingBottomImage setClipsToBounds:YES];
CGRect underViewFrame = underView.frame;
underViewFrame.origin.y = containerY;
underView.frame = underViewFrame;
[openingContainer addSubview:underView];
[openingContainer addSubview:topView];
[openingContainer addSubview:openingBottomImage];
[topView release];
[self.view.superview addSubview:openingContainer];
[UIView animateWithDuration:0.5f animations:^(void) {
CGRect bottomImageFrame = openingBottomImage.frame;
bottomImageFrame.origin.y += underView.frame.size.height;
openingBottomImage.frame = bottomImageFrame;
}];
}];
openingOpen = YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment