使用drawViewHierarchyInRect:afterScreenUpdates方法截图的代码:
#pragma mark - 截取当前屏幕
- (NSData*)dataWithScreenshotInPNGFormat
{
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 0.0);
if([self.viewrespondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];//
}
else{
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return UIImageJPEGRepresentation(image,0.2);
}
此方法截图不显示导航栏,使用[UIScreen mainScreen].bounds能截图出导航栏
网友评论