I have a number of full screen CALayers as part of a single UIView. Depending on how the user interacts with the view, I need to show one layer and hide all others. I'm currently doing this by changing the opacity, i.e.
Layer to hide: [layer setOpacity:0]; Layer to show: [layer setOpacity:1];
For a reason I don't quite understand, this seems to create a flashing effect on the screen. Partially to avoid this, but also because I have the impression that opacity changes can affect performances, I'm wondering if changing opacity is actually the best way to hide and/or show CALayers, e.g. should I consider changing the zPosition or changing its position so that it no longer appears on screen.
I don't want to animate the transition by the way.
Thanks in advance for any pointers or help.
The normal way to hide a layer is setting its hidden
property to YES
, but it's no harm to set its opacity
to 0.0 to achieve that, which depends on your usage scenario.
If your CALayer
is not your UIView
's underlying layer(the UIView
instance's layer
property), change the opacity
or hidden
properties will trigger animation by default. To prevent that, add this code before changing these properties:
[CATransaction setDisableActions:YES];
CALayer has a property called "hidden", try setting that to YES and NO instead of switching opacities.
Layer to hide: [layer setHidden:YES];
Layer to show: [layer setHidden:NO];
Hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With