I have trouble with deleting all of layer's sublayers. I currently do this manually, but that brings unnecessary clutter. I found many topics about this in google, but no answer.
I tried to do something like this:
for(CALayer *layer in rootLayer.sublayers) { [layer removeFromSublayer]; }
but it didn't work.
Also, i tried to clone rootLayer.sublayers into separate NSArray, but result was the same.
Any ideas?
Edit:
I thought it works now, but I was wrong. It works good with CALayers, but it doesn't work with CATextLayers. Any ideas?
Swift 3.0 & Swift 4.0Set the sublayers property to nil to remove all sublayers from a view.
Overview. Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer's main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow.
The simplest way to remove all sublayers from a layer is to set the sublayer property to nil:
rootLayer.sublayers = nil;
The following should work:
for (CALayer *layer in [[rootLayer.sublayers copy] autorelease]) { [layer removeFromSuperlayer]; }
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