简体   繁体   中英

How to draw multiple CALayer sublayers from parent layer

I have a CALayer with two subLayers that contain semi-static content. While rendering the top layer I would like to occasionally just go ahead and render the sublayers without scheduling an update with setNeedsDisplay.

I know that one option is to create delegate classes and implement drawLayer:inContext: but I wanted to render the sublayers immediately perhaps with renderInContext: but I don't want to render into the parent layer.

Is there a way I can switch or obtain the context of the sublayers to do immediate drawing into them?

The mechanism for doing the drawing while holding on to the state in a "root" object is to set the root object as the delegate for any layer for which it will do the rendering. Then you should implement drawLayer:inContext: in the delegate.

Note that a layer will not require redrawing unless you ask it to with setNeedsDisplay. So in your case, would would loop through your state and call [layer setNeedsDisplay] only those layers that need it and in turn only those layers will call drawLayer:inContext:.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM