Last active
January 2, 2016 21:19
-
-
Save alexrothenberg/8362158 to your computer and use it in GitHub Desktop.
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)someBigMethod { | |
// create a screenshot | |
CALayer * screenLayer = [[[[[UIApplication sharedApplication] keyWindow] rootViewController] view] layer]; | |
CGFloat const shotScale = ([[UIScreen mainScreen] scale] / 2.0); | |
UIGraphicsBeginImageContextWithOptions(screenLayer.bounds.size, YES, shotScale); | |
[screenLayer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
// put the screenshot in a layer | |
CALayer * bgLayer = [[CALayer alloc] init]; | |
bgLayer.contentsScale = shotScale; | |
bgLayer.rasterizationScale = shotScale; | |
bgLayer.opaque=YES; | |
bgLayer.bounds = CGRectMake(0, 0, screenshot.size.width, screenshot.size.height); | |
bgLayer.contents = (id) screenshot.CGImage; | |
// lots more lines to do more stuff | |
} |
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)someBigMethod { | |
UIImage* screenshot = createScreenshot(); | |
CALayer * bgLayer = putScreenshotInALayer(screenshot); | |
// lots more 1 line function calls | |
} | |
// with a bunch of private helper methods that each do one thing like | |
-(UIImage*)createScreenshot { | |
CALayer * screenLayer = [[[[[UIApplication sharedApplication] keyWindow] rootViewController] view] layer]; | |
CGFloat const shotScale = ([[UIScreen mainScreen] scale] / 2.0); | |
UIGraphicsBeginImageContextWithOptions(screenLayer.bounds.size, YES, shotScale); | |
[screenLayer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return screenshot; | |
} | |
-(CALayer*)putScreenshotInALayer(UIImage *)screenshot { | |
CALayer * bgLayer = [[CALayer alloc] init]; | |
bgLayer.contentsScale = shotScale; | |
bgLayer.rasterizationScale = shotScale; | |
bgLayer.opaque=YES; | |
bgLayer.bounds = CGRectMake(0, 0, screenshot.size.width, screenshot.size.height); | |
bgLayer.contents = (id) screenshot.CGImage; | |
return bgLayer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment