UIImage* image = nil;
UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0);
{
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();
我无法获得滚动视图的完整图像,但只有一半,而一半是黑色
答案 0 :(得分:1)
修改强>
尝试添加
drawHierarchy(in: self.bounds, afterScreenUpdates: true)
行后
[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];