Skip to content

Instantly share code, notes, and snippets.

@jrturton
Created February 1, 2013 12:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrturton/4690976 to your computer and use it in GitHub Desktop.
Save jrturton/4690976 to your computer and use it in GitHub Desktop.
switch out a screenful of content for another one, in a left or right direction.
-(void)changeArticle:(UIButton*)sender
{
CGFloat multiplier = (sender == self.nextButton) ? 1.0 : -1.0;
// Render to an image and drop in the new version
UIGraphicsBeginImageContextWithOptions(self.articleContainer.frame.size, YES, 0);
CGContextRef c = UIGraphicsGetCurrentContext();
[self.articleContainer.layer renderInContext:c];
UIImage *articleScreenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *screenshotView = [[UIImageView alloc] initWithImage:articleScreenshot];
screenshotView.center = self.articleContainer.center;
[self.contentView insertSubview:screenshotView aboveSubview:self.articleContainer];
// Shift out the article view
CGFloat moveBy = self.articleContainer.frame.size.width * multiplier;
CGPoint center = self.articleContainer.center;
self.articleContainer.center = CGPointMake(center.x + moveBy,center.y);
//Update the article view with the new information
NSInteger nextItem = self.currentFundItemIndex + multiplier;
self.currentFundItemIndex = nextItem;
sender.transform = CGAffineTransformMakeScale(0.97, 0.97);
[UIView animateWithDuration:0.3 animations:^{
screenshotView.center = CGPointMake(center.x - moveBy,center.y);
self.articleContainer.center = center;
} completion:^(BOOL finished) {
[screenshotView removeFromSuperview];
sender.transform = CGAffineTransformIdentity;
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment