我有一个水平滚动的 Collection View 。我需要从 Collection View 的当前可见部分创建一个 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;
}
但它在滚动后不适用于 Collection View,因为它似乎正在获取已滚动到屏幕之外的 View 的一部分
最佳答案
代替
[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
你应该使用
[inputView drawViewHierarchyInRect:inputView.frame afterScreenUpdates:YES];
关于ios - 从 UICollectionView 可见区域创建 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23551734/