Removing all CALayer's sublayers

前端 未结 15 1033
说谎
说谎 2020-12-07 20:25

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 a

15条回答
  •  执笔经年
    2020-12-07 20:41

    For swift3+,You can use this.

    yourView.layer.sublayers?.removeAll(keepingCapacity: true)

    See here: Apple API Reference

    Or you can: yourView.layer.sublayers?.forEach{ $0.removeFromSuperlayer()}

提交回复
热议问题