简体   繁体   中英

Draw order using CAGradientLayer & drawRect:(CGRect)

My view overrides the drawRect method to render graphics .

And I've recently added a gradient background using CAGradientLayer and [view.layer insertSubLayer: atIndex:0]

However the CAGradientLayer gets drawn over my graphics instead of underneath. Setting alpha of the gradient colours 0.5 shows that my graphics are still being drawn.

This is an app with a high graphics refresh rate, I cannot afford to redraw a gradient on every refresh so was counting on the CAGradientLayer's backing store to keep things performant.

How should I approach this?

Thank you!

Sublayers are always drawn on top of the base layer, much like subviews are always drawn on top of the base view.

What you could try is work at the superview's level, and add a gradient sublayer to it. It will be displayed below your view.

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