iphone - 重复的 UIView

标签 iphone objective-c ios

我想多次显示同一个 UIView。目前,我在主 UIView 中绘制了图形,然后使用 renderInContext: 和 UIGraphicsGetImageFromCurrentImageContext 将其复制到图像中。然后我将其他代理 UIView 的内容设置为该图像。

 UIGraphicsBeginImageContext(size);

 [self.layer renderInContext:UIGraphicsGetCurrentContext()];

 UIImage * clonedImage = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

 return [clonedImage CGImage];

我在 renderInContext: 调用中遇到瓶颈,大概是因为它必须复制 View 的图像。我在 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/

相关文章:

ios - 如何在swift中播放电影

objective-c - iOS - 合并两个不同大小的图像

iphone - 按钮的目标始终是 "self"?我可以设置为另一个吗?

iphone - 在不越狱的情况下将自定义应用程序加载到 iOS 设备中?

iphone - 无法关闭 iPhone 中的电子邮件编辑器 View ?

iphone - 仅更新到 iOS 8 后,旧版 iOS 7 应用程序是否仍可在 AppStore 中使用?

ios - Objective c 拆分字符串问题

ios - NSDictionary 和 JSON 值

ios - 无法推送 ViewController iOS

ios - UserDefault 总是返回 nil