如何对 UIScrollView 可见区域进行 1:1 截图?内容可能大于或小于 UIScrollView 边界以及半隐藏(我已经为较小的内容实现了自定义滚动,所以它不在左上角)。我在模拟器上达到了预期的效果,但在设备本身上却没有:
-(UIImage *)imageFromCombinedContext:(UIView *)background {
UIImage *image;
CGRect vis = background.bounds;
CGSize size = vis.size;
UIGraphicsBeginImageContext(size);
[background.layer affineTransform];
[background.layer renderInontext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imref = CGImageCreateWithImageInRect([image CGImage], vis);
image = [UIImage imageWithCGImage:imref];
CGImageRelease(imref);
return image;
}