title: Add semi-transparent mask to CALayer?
body: <p>I'm trying to darken the surrounding area of my UIImageView, and leave a portion alone (which I define with my mask).</p>
  
  <p>Right now I'm defining my mask and setting my imageView.layer.mask, however instead of darkening the rest of the image, it's completely removing it instead.</p>
  
  <p>Example of the type of effect I want: <img src="https://i.stack.imgur.com/n68zq.png" alt="http://i.imgur.com/vVUiuyk.png"></p>
  
  <p>Example of what I'm getting: <img src="https://i.stack.imgur.com/sAfd3.png" alt="http://i.imgur.com/5DTXo0S.png"></p>
  
  <p>The reference docs mention that the mask uses it's layer's alpha, so I've tried manipulating the mask's opacity. However, that only seems to affect the opacity of the portion I want to leave alone, while the rest of the image is still being cut out completely.</p>
  
  <p>Can anyone point out what I'm doing wrong? Thanks.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>CAShapeLayer *mask = [CAShapeLayer layer];
  GMutablePathRef path = CGPathCreateMutable();
  
  CGPathMoveToPoint(path, nil, 1052, 448);
  CGPathAddLineToPoint(path, nil, 2, 484);
  CGPathAddLineToPoint(path, nil, 54, 1263);
  CGPathAddLineToPoint(path, nil, 56, 1305);
  CGPathAddLineToPoint(path, nil, 380, 1304);
  CGPathAddLineToPoint(path, nil, 1050, 1311);
  CGPathCloseSubpath(path);
  mask.path = path;
  CGPathRelease(path);
  
  //mask.opacity = 0.5; //doesn't affect the surrounding portion, only the cut out area.
  self.imageView.layer.mask = mask;
  </code></pre>