-
-
Save Kila2/b4a9e0c218f4ffdd81502a8da5029d8a to your computer and use it in GitHub Desktop.
getSnapshotFromView
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
+ (nullable UIImage *)getSnapshotFromView:(UIView *)view useScreenUpdate:(BOOL)useScreenUpdate | |
{ | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [UIScreen mainScreen].scale); | |
UIImage * snapshotImage = NULL; | |
if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)] && useScreenUpdate) { | |
BOOL drawSuccess = [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; | |
if (drawSuccess) { | |
snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); | |
} | |
} else { | |
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); | |
} | |
UIGraphicsEndImageContext(); | |
return snapshotImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment