Created
February 1, 2013 12:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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