문제

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top