Created
October 8, 2013 14:17
-
-
Save Geri-Borbas/6885413 to your computer and use it in GitHub Desktop.
Three way to create UIView snapshot containing SpriteKit content.
This file contains hidden or 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
-(UIImage*)snapshotUsingPrivateApi | |
{ | |
// Works fine, but private. | |
CGImageRef snapshot = UIGetScreenImage(); | |
UIImage *snapshotImage = [UIImage imageWithCGImage:snapshot]; | |
return snapshotImage; | |
} | |
-(UIImage*)snapshotUsingDrawHierarchy | |
{ | |
// Captures SpriteKit content! | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale); | |
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; | |
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return snapshotImage; | |
} | |
-(UIImage*)snapshotUsingLayer | |
{ | |
// Captures UIKit content only. | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale); | |
[self.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return snapshotImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment