I have a collection view that scrolls horizontally. I need to create a UIImageView from the currently visible portion of the collection view.
I usually use the following method for this:
+ (UIImageView *) imageCopyOfView:(UIView *)inputView
{
UIGraphicsBeginImageContext(inputView.bounds.size);
[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *retView = [[UIImageView alloc] initWithImage:viewImage];
return retView;
}
but it does not work with the Collection View after it has been scrolled as it seems to be getting a portion of the view that has been scrolled off the screen
Instead of
[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
you should use
[inputView drawViewHierarchyInRect:inputView.frame afterScreenUpdates:YES];