// 开启上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0);
// 获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 渲染控制器view的图层到上下文
// 图层只能用渲染不能用draw
[self.view.layer renderInContext:ctx];
// 获取截屏图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 关闭上下文
UIGraphicsEndImageContext();
NSData *data = UIImagePNGRepresentation(newImage);
//截屏后存放位置
[data writeToFile:@”/Users/soccer/Desktop/layer.png” atomically:YES];
}
截屏
