gpt4 book ai didi

ios - 从 UICollectionView 可见区域创建 UIImage

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:23:22 24 4
gpt4 key购买 nike

我有一个水平滚动的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com