This article mainly introduces the example code for iOS screenshotting view, and shares it with you, as follows:
You need to take a screenshot of WKWebView. I used the following method before. There is no problem with the higher version of the system, but the lower version of the screening of a white picture.
- (UIImage *)convertViewToImage:(UIView *)view{ // The second parameter indicates whether it is non-transparent. If you need to display a translucent effect, you need to pass NO, otherwise YES. The third parameter is the screen density UIGraphicsBeginImageContextWithOptions(CGSizeMake(, * 0.8),YES,[UIScreen mainScreen].scale); [ renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
After checking, I found that there was a problem with the level and the top view was not captured, so I just changed to the following method.
- (UIImage*)captureView:(UIView *)theView frame:(CGRect)frame{ UIGraphicsBeginImageContextWithOptions(CGSizeMake(, *0.8), YES, [UIScreen mainScreen].scale); CGContextRef context = UIGraphicsGetCurrentContext(); UIImage *img; if([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0){ for(UIView *subview in ){ [subview drawViewHierarchyInRect: afterScreenUpdates:YES]; } img = UIGraphicsGetImageFromCurrentImageContext(); }else{ CGContextSaveGState(context); [ renderInContext:context]; img = UIGraphicsGetImageFromCurrentImageContext(); } UIGraphicsEndImageContext(); return img; }
Note that frame cannot be empty, and if the intercept is too fast, there will be problems. You need to set afterScreenUpdates to NO, because after setting to YES, these methods will wait until the view update is finished before execution. If the view is released before the update ends, the view will not be found. Also remember to use UIGraphicsBeginImageContextWithOptions, so that the clipping of high-definition images is a high-definition image.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.