I create a view at run time and I use it’s drawRect: to draw a figure on it. In the next step I add a sublayer with contents of an image to the layer of the view and then I show it. It works. But the figure on the view is still shown below the image. With view.layer.contents = nil; before creating the sublayer, the figure on the view is removed. But I need to show it again. With [view setNeedsDisplay]; (calling drawRect:) I can draw it again.
Is there any (easier) way to hide (or cover) this figure and show it again (without removing and redrawing it)? Thanks.
Edit:
I can do this: layer.backgroundColor = [UIColor blackColor].CGColor; the figure is covered. But the backgroundColor must be transparent. Thanks very much for another ideas.
You can use:
If you only want to hide and show a sublayer, you can keep hold of a reference to that sublayer, or find it by looking in
view.layer.sublayers.