I am using standard code to take a full screenshot of a scrollview. It works for most scenarios. However, I have a UICollectionView that uses AFNetworking's setImageWithURL to retrieve images. I want the user to be able to print or email the entire content with all images displayed. The problem is, if the offscreen images have not been scrolled to by the user, the screenprint always show the placeholder "Image Not Found" image.
My code:
UIGraphicsBeginImageContext(scrollView.contentSize);
{
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect savedFrame = scrollView.frame;
scrollView.contentOffset = CGPointZero;
scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
[scrollView drawViewHierarchyInRect:scrollView.frame afterScreenUpdates:NO];
else
[scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
scrollView.contentOffset = savedContentOffset;
scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
I've tried putting the thread to sleep to "wait" for the images to get loaded but that didn't work. Ideas would appreciated. Thanks!