如何获取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;
}
Run Code Online (Sandbox Code Playgroud) 我有一个UIImageView带UIViewContentModeCenter,因此,它拥有图片没有得到缩放或变形.但是这样,如果图像更大,可以在ImageView的框架外看到它.我不想裁剪图像(用户可以缩放图像,因此数据丢失不是一种选择),但我需要将其中的一部分ImageView视为隐形或其他东西