就像您在我的代码中看到的那样,我会截屏并将其保存到相册中。
//for retina displays
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
一开始我使用了webview.size
而非self.view.bounds.size
,因为视图位于0/0
位置,所以它运作正常。但现在我将WebView居中,但是图片从给定尺寸的0/0
开始。
如何配置截图从另一个位置(例如300/150
)开始呢?
或者还有其他方法可以对UIWebView
进行截图吗?