Ios 从UICollectionView可见区域创建UIImage

Ios 从UICollectionView可见区域创建UIImage,ios,uicollectionview,uigraphicscontext,Ios,Uicollectionview,Uigraphicscontext,我有一个水平滚动的集合视图。我需要从集合视图的当前可见部分创建UIImageView 为此,我通常使用以下方法: + (UIImageView *) imageCopyOfView:(UIView *)inputView { UIGraphicsBeginImageContext(inputView.bounds.size); [inputView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage

我有一个水平滚动的集合视图。我需要从集合视图的当前可见部分创建UIImageView

为此,我通常使用以下方法:

+ (UIImageView *) imageCopyOfView:(UIView *)inputView
{
    UIGraphicsBeginImageContext(inputView.bounds.size);
    [inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageView *retView = [[UIImageView alloc] initWithImage:viewImage];
    return retView;
}
但它在滚动后不适用于集合视图,因为它似乎获得了从屏幕上滚动下来的视图的一部分,而不是

[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
你应该使用

[inputView drawViewHierarchyInRect:inputView.frame afterScreenUpdates:YES];

嗯,这是不同的,但不完全一样。但我在动画中使用了捕获的图像,这可能会把它搞砸。继续看。这可能已经得到了它,但我可能只是有其他的东西造成了一个问题。谢谢你的回复。我将继续使用它。经过一些修补后,我发现问题在于调用它的方法中的框架存在问题。你的解决方案正是我需要的。谢谢