title: CALayer with transparent hole in it
body: <p>I have a simple view (left side of the picture) and i need to create some kind of overlay (right side of the picture) to this view. This overlay should have some opacity, so the view bellow it is still partly visible.
  Most importantly this overlay should have a circular hole in the middle of it so it doesn't overlay the center of the view (see picture bellow). </p>
  
  <p>I can easily create a circle like this :</p>
  
  <pre><code>int radius = 20; //whatever
  CAShapeLayer *circle = [CAShapeLayer layer];
  
  circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0,radius,radius) cornerRadius:radius].CGPath;
  circle.position = CGPointMake(CGRectGetMidX(view.frame)-radius,
                                CGRectGetMidY(view.frame)-radius);
  circle.fillColor = [UIColor clearColor].CGColor;
  </code></pre>
  
  <p>And a "full" rectangular overlay like this :</p>
  
  <pre><code>CAShapeLayer *shadow = [CAShapeLayer layer];
  shadow.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height) cornerRadius:0].CGPath;
  shadow.position = CGPointMake(0, 0);
  shadow.fillColor = [UIColor grayColor].CGColor;
  shadow.lineWidth = 0;
  shadow.opacity = 0.5;
  [view.layer addSublayer:shadow];
  </code></pre>
  
  <p>But I have no idea how can I combine these two layers so they create effect I want. Anyone? I've tried really everything... Thanks a lot for help!</p>
  
  <p><img src="https://i.stack.imgur.com/o1jyS.png" alt="Image"></p>