Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###Generating a screenshot
- ```objective-c
- - (UIImage *)screenshot
- {
- CGSize imageSize = CGSizeZero;
- imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
- UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
- CGContextRef context = UIGraphicsGetCurrentContext();
- for (UIWindow *window in [[UIApplication sharedApplication] windows])
- {
- CGContextSaveGState(context);
- CGContextTranslateCTM(context, window.center.x, window.center.y);
- CGContextConcatCTM(context, window.transform);
- CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
- if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
- {
- [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
- }
- else
- {
- [window.layer renderInContext:context];
- }
- CGContextRestoreGState(context);
- }
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement