how to redraw only one specific layer ? (IOS,SWIFT)

I have my UIView. I draw something in my UIView. I added a CALayer to my UIView. Now I would like my controller to only redraw my added CALayer.

How do I do that ?

  • Creating a blurring overlay view
  • Need better and simpler understanding of CATransform3D
  • CABasicAnimation rotate returns to original position
  • touchesMoved drawing in CAShapeLayer slow/laggy
  • Display UIView with a UILabel text mask
  • How can I add shadow to a circle UIImageView or UIView?
  • In my actual Code it will redraw the main view. How can I redraw my subview (myshapelayer) ?

         override func drawRect(rect: CGRect) {
                var myshapelayer:CAShapeLayer=CAShapeLayer();
                var testbezier:UIBezierPath=UIBezierPath();
                testbezier.moveToPoint(CGPoint(x: 60, y: 80));
    <draw on my main view>



    2 Solutions Collect From Internet About “how to redraw only one specific layer ? (IOS,SWIFT)”

    There are two ways.

    First, you make delegate protocol and pass your CALayer to change in ViewController

    Second, you can get CALayer by using self.view.subviews
    if CALayer‘s index is 1, you can get CALayer object by self.view.subviews[1] as? CALayer

    Hope that it may help you.

    you can call


    from ViewController