我正在尝试拍摄 UIScrollView 的所有内容的快照,我在 SO 上找到了一些代码,下面的代码工作了一半,因为快照是所有 uiscrollview 的,但背景是黑色的,这个是代码:
UIImage* image = nil;
UIGraphicsBeginImageContextWithOptions(_scrollView.contentSize,YES,0.0f);
{
CGPoint savedContentOffset = _scrollView.contentOffset;
CGRect savedFrame = _scrollView.frame;
_scrollView.contentOffset = CGPointZero;
_scrollView.frame = CGRectMake(0, 0, _scrollView.contentSize.width, _scrollView.contentSize.height);
[_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
_scrollView.contentOffset = savedContentOffset;
_scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
我怎么能在快照中也有背景?