title: Reverse a CALayer mask
body: <p><a href="https://i.stack.imgur.com/ATdKg.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ATdKg.jpg" alt="enter image description here"></a>I am trying to use a CALayer with an image as contents for masking a UIView. For the mask I have complex png image. If I apply the image as a view.layer.mask I get the opposite behaviour of what I want. 
  Is there a way to reverse the CAlayer? Here is my code:</p>
  
  <pre><code>layerMask = CALayer()
  guard let layerMask = layerMask else { return }    
  layerMask.contents = #imageLiteral(resourceName: "mask").cgImage
  view.layer.mask = layerMask
  // What I would like to to is
  view.layer.mask = layerMask.inverse. // &lt;---
  </code></pre>
  
  <p>I have seen several posts on reverse CAShapeLayers and Mutable paths, but nothing where I can reverse a CALayer. 
  What I could do is reverse the image in Photoshop so that the alpha is inverted, but the problem with that is that I won't be able to create an image with the exact size to fit all screen sizes. I hope it does make sense.</p>