title: How to apply CAGradientLayer as mask of another CALayer?
body: <p>I have a view, which has a CALayer. When I create a CAGradientLayer and apply it as the mask of that view's CALayer, nothing happens. Why?</p>
  
  <p>In -initWithFrame: of the view I do this:</p>
  
  <pre><code>CAGradientLayer *gradient = [CAGradientLayer layer];
  gradient.frame = self.bounds;
  gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
  //[self.layer insertSublayer:gradient atIndex:0];
  self.layer.mask = gradient;
  </code></pre>
  
  <p>If I replace </p>
  
  <pre><code>self.layer.mask = gradient;
  </code></pre>
  
  <p>with </p>
  
  <pre><code>[self.layer insertSublayer:gradient atIndex:0];
  </code></pre>
  
  <p>then I see the gradient. It's from black to white.</p>
  
  <p>What's the trick?</p>