2

我有一个水平滚动的集合视图。我需要从集合视图的当前可见部分创建一个 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;
}

但它在滚动后不适用于集合视图,因为它似乎正在获取已从屏幕滚动的视图的一部分

4

1 回答 1

1

代替

[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];

你应该使用

[inputView drawViewHierarchyInRect:inputView.frame afterScreenUpdates:YES];
于 2014-05-08T20:49:17.547 回答