我想多次显示相同的UIView。目前,我将绘图放在主UIView中,然后使用renderInContext:和UIGraphicsGetImageFromCurrentImageContext将其复制到图像中。然后,将其他代理UIView的内容设置为此图像。
UIGraphicsBeginImageContext(size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * clonedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [clonedImage CGImage];
我在renderInContext:调用中遇到瓶颈,大概是因为它必须复制视图的图像。我在resample_byte_h_3cpp和resample_byte_v_Ncpp中看到热点,但是我不确定它们在做什么。
是否可以多次显示相同的UIView来减少此开销?还是有一种更有效的方法来渲染图像?
最佳答案
如何制作UIImage的副本而不是一遍又一遍地从UIView生成新图像?
//.. Create the clonedImage from UIView
CGImageRef cgImageRef = [clonedImage CGImage];
UIImage *twinImage = [[UIImage alloc] initWithCGImage:cgImageRef];
//.. Use the images
[clonedImage release]; // if needed
[twinImage release]; // if needed
关于iphone - 重复的UIView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4081220/