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?
In -initWithFrame: of the view I do this:
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;
If I replace
self.layer.mask = gradient;
with
[self.layer insertSublayer:gradient atIndex:0];
then I see the gradient. It's from black to white.
What's the trick?