开发者

Duplicate UIViews

I'd like to display the same UIView multiple times. At the moment, I have my drawing in a primary UIView, then copy this into an image using renderInContext: and UIGraphicsGetImageFromCurrentImageContext. Then I set the contents of the other proxy UIViews to be this image.

 UIGraphicsBeginImageContext(size);

 [self.layer renderInContext:UIGraphicsGetCurrentContext()];

 UIImage * clonedImage = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

 return [clonedImage CGImage];

I'm experiencing a bottleneck in the renderInContext: call, presumably 开发者_运维技巧because it has to copy the image of the view. I'm seeing hot spots in resample_byte_h_3cpp and resample_byte_v_Ncpp, but I'm not sure what these are doing.

Is it possible to display the same UIView multiple times to reduce this overhead? Or is there a more efficient way to render the image?


How about making a copy of the UIImage instead of generating new images over and over from the 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜