OGeek|极客世界-中国程序员成长平台

标题: ios - 从 UICollectionView 可见区域创建 UIImage [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:15
标题: ios - 从 UICollectionView 可见区域创建 UIImage

我有一个水平滚动的 Collection View 。我需要从 Collection View 的当前可见部分创建一个 UIImageView。

我通常使用以下方法:

+ (UIImageView *) imageCopyOfViewUIView *)inputView
{
    UIGraphicsBeginImageContext(inputView.bounds.size);
    [inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageView *retView = [[UIImageView alloc] initWithImage:viewImage];
    return retView;
}

但它在 Collection View 滚动后无法使用,因为它似乎正在获取已滚动出屏幕的 View 的一部分



Best Answer-推荐答案


代替

[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];

你应该使用

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

关于ios - 从 UICollectionView 可见区域创建 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23551734/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4