Show by time a sublayer, Swift 3

0

I would like to show for a certain time (2 seconds) a circular sublayer that is in my function pointCamera . But I can not find a way to do it, this is my code:

func pointCamera(centerPoint: CGPoint) {

    let circlePath = UIBezierPath(arcCenter: centerPoint, radius: CGFloat(30), startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2), clockwise: true)

    let shapeLayer = CAShapeLayer()
    shapeLayer.path = circlePath.cgPath

    shapeLayer.fillColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 0.3).cgColor
    shapeLayer.strokeColor = UIColor(red: 0, green: 191/255, blue: 1, alpha: 0.9).cgColor
    shapeLayer.lineWidth = 2.0

    cameraView.layer.addSublayer(shapeLayer)

}
    
asked by Sebastián Varella Gmz 12.03.2017 в 04:53
source

2 answers

0

Well, what I think you have to do is 2 seconds after putting the shapelayer, then remove it

after including it with the cameraView.layer.addSublayer (shapeLayer) you do a delay

    let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
    dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in
        shapeLayer.removeFromSuperLayer()
    }
    
answered by 12.03.2017 в 10:15
0

Effectively with a dispatch after should work for you. This is how you will need to do it in Swift 3:

...

    cameraView.layer.addSublayer(shapeLayer)
    DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
        shapeLayer.removeFromSuperlayer()
    })
    
answered by 13.03.2017 в 21:22