删除所有CALayer的子图层 [英] Removing all CALayer's sublayers

查看:196
本文介绍了删除所有CALayer的子图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法删除图层的所有子图层。我目前手动这样做,但这带来不必要的杂乱。

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.

我尝试做这样的事情:


for(CALayer *layer in rootLayer.sublayers)
{
    [layer removeFromSublayer];
}

但不起作用。

,我试图克隆rootLayer.sublayers到单独的NSArray,但结果是一样的。

Also, i tried to clone rootLayer.sublayers into separate NSArray, but result was the same.

任何想法?

编辑:

我以为它现在工作,但我错了。它适用于CALayers,但它不工作与CATextLayers。任何想法?

I thought it works now, but I was wrong. It works good with CALayers, but it doesn't work with CATextLayers. Any ideas?

推荐答案

从图层中删除所有子图层的最简单的方法是将sublayer属性设置为nil:

The simplest way to remove all sublayers from a layer is to set the sublayer property to nil:

rootLayer.sublayers = nil;

这篇关于删除所有CALayer的子图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆