You are very close ...
You have:
@IBOutlet weak var shapeLayer: UIView!
but then you also create a CAShapeLayer named shapeLayer:
let shapeLayer = CAShapeLayer()
which you add as a sublevel of your "main" view. Then you add all the rest on top of your main view, covering the shapeLayer.
In viewDidLoad (), change the section with the blue circle to the picture:
let midX = self.view.bounds.midX let midY = self.view.bounds.midY let circlePath = UIBezierPath(arcCenter: CGPoint(x: midX,y: midY), radius: CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true) let shapeLayerPath = CAShapeLayer() shapeLayerPath.path = circlePath.cgPath
Then, at the end of beginSession () ...
self.view.addSubview(navigationBar) self.view.addSubview(imgOverlay) self.view.addSubview(btnCapture) // shapeLayer ImageView is already a subview created in IB // but this will bring it to the front self.view.addSubview(shapeLayer) // note: since these elements are added as @IBOutlet in IB, // these could be: // self.view.bringSubview(toFront: navigationBar) // self.view.bringSubview(toFront: imgOverlay) // self.view.bringSubview(toFront: btnCapture) // self.view.bringSubview(toFront: shapeLayer)
See what you get :)
Edit: The next question moved to Combining Images in CameraView with Overlay. (Swift 3)?
source share