This is somewhat of a hypothetical question, but I can imagine this situation coming up at some point in the future: Let's assume for a moment that I have a freakishly complicated hierarchy of UIViews that I'd need to render only once. Let's also assume that, once drawn, I have no further use for the information (UIImages, labels, custom views, coords, etc.) beneath the parent view. Rather than retaining them, the idea is to free all the extra memory they use while avoiding a redraw. The result would be the same as drawing to an offscreen buffer and then pushing it onscreen. Is it possible to achieve this using UIView/CGLayer right 开发者_开发百科out of the box, or is the only option to convert the content of the parent CGLayer into a UIImage?
Just curious. I'd imagine in most situations the overhead of keeping a few extra views around is negligible, but memory is memory, and I haven't been able to find anything on it in the official docs beyond allocating bitmaps.
Thanks!
This strikes me as something very risky. Things beyond your control may happened that require the view to be redrawn, such as a notification appearing or the view being effected by the phone call active green bar thingy at the top of the screen.
I suggest that if you have that many views in your hierarchy there will be so many other performance problems that come into play that saving a few bytes after redraw will be the least of your problems.
I can think about overriding -(void)drawRect:(CGRect)rect;
method, drawing only once to offscreen before moving that image to the screen according to some boolean flag, but it may lead to a monstrous bugs and should be desined properly. Another thing is that it may lead to overriding also the -(void)layoutSubviews;
, thought it may be overhead if you've overriden the firs one...
精彩评论