I am not explicitly setting my sublayers’ opacity — only the superlayer’s via the opacity property. While the superlayer’s opacity does change as expected, my sublayers’ opacities also appear to change, causing elements below those sublayers within the superlayer to be exposed. Why might this be happening?
I am not explicitly setting my sublayers’ opacity — only the superlayer’s via the
Share
Why is this surprising you? What did you expect to happen? If you don’t want this, don’t put those sublayers inside that superlayer. Just put them on top of it (perhaps in a separate superlayer).
EDIT: I understand your issue now. You’re running into a Core Animation optimization. Core Animation is trying to save time by just applying the opacity to all the sublayers prior to compositing. That way it can composite just one time (which lets it ignore the container superlayer). Most of the time this works out and improves performance.
What you want it to do is all the compositing within the superlayer, then apply the opacity, and then re-composite the result with everything else. This is called rasterizing; which basically means “please turn me into a bitmap before you composite me with anything else.” You can request this by setting
shouldRasterizeon your superlayer.