Removing all CALayer's sublayers

前端 未结 15 1041
说谎
说谎 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:37

    You could simply provide an identifier for the CAlayer you have added and remove it by searching for it. Like so

     let spinLayer = CAShapeLayer()
     spinLayer.path = UIBezierPath()
     spinLayer.name = "spinLayer"
    
    
      func removeAnimation() {
         for layer in progressView.layer.sublayers ?? [CALayer]()
             where layer.name == "spinLayer" {
               layer.removeFromSuperlayer()
           }
       }
    

提交回复
热议问题