I have a UIIMageView inside the view of a UIVIewController. I have drawn a rectangle - UIBezierPath in the layer of the root view and I would like to fill just the outside of the rectangle and leave the inside of the rectangle unfilled so that one can see through to the image below it. Below is my attempt but it fills the rectangle and not the outside of the rectangle.
let rectHoleSize = CGRect.init(x: myRectangle.frame.minX, y: myRectangle.frame.minY, width: myRectangle.frame.width, height: myRectangle.frame.height)
let path = UIBezierPath.init(rect: rectHoleSize)
path.usesEvenOddFillRule = true
let layer = CAShapeLayer()
layer.path = path.cgPath
layer.fillRule = .evenOdd
layer.fillColor = view.backgroundColor?.cgColor
layer.opacity = 0.5
view.layer.addSublayer(layer)