.m文件中引入
#import<QuartzCore/QuartzCore.h>
- (UIImage *) captureScreen {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[keyWindow.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)saveScreenshotToPhotosAlbum:(UIView *)view
{
UIImageWriteToSavedPhotosAlbum([self captureScreen], nil, nil, nil);
}