2

I have a main layer, that has a mask layer.

The mask layer has also sublayers (to change layouts within resulting different mask shapes).

But the mask sublayers have no effect on the actual masking. :(

Is there something I can do with the mask layer? I want to use it in an animation, so performance also a focus.


The mask layer is full white at start, then I put in smaller black/grayscale content, and I just want to see the result. Can I mask a CALayer with a grayscale image at all?


// Disable layer actions with this delegate object.
self.layerDelegate = [TCLayerDelegate new];

// Create.
CALayer *layer = [CALayer layer];
layer.delegate = self.layerDelegate;

// Setup.
layer.contents = (id)self.colorImage.CGImage; // A simple opaque image with a color.
layer.frame = (CGRect){CGPointZero, self.size};
layer.anchorPoint = (CGPoint){ 0.0, 0.5 };

// Align.
self.layer.position = self.a;

// Create mask.
self.maskLayer = [CALayer layer];
self.maskLayer.delegate = self.layerDelegate;

// Setup.
self.maskLayer.contents = (id)self.maskImage.CGImage; // A black opaque image for now.
self.maskLayer.frame = (CGRect){CGPointZero, self.size};

// Add mask.
self.layer.mask = self.maskLayer;

// Add circles.
[self.circle createLayer]; // This object amongst many other things creates a transparent layer that holds a white circle.

// Add to mask.
[self.maskLayer addSublayer:self.circle.layer];

// Now I'd like to see layer masked with the circle.
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
  • Can you post some code how you set these layers up? – Unheilig Oct 10 '13 at 18:33
  • 'Course, thanks, there it goes. – Geri Borbás Oct 11 '13 at 09:48
  • try to figure out where your layers are (layer.borderColor/width) and comment out setting the layer.delegate. I can't actually see how your mask layers are constructed. Try to use a simple CAShapeLayer with a circle filled with black. – Bernd Rabe Oct 12 '13 at 10:11
  • Elsewhere. The parent object has a self.size property, the method self.colorImage returns a UIImage with that size. Already headed to CAShapeLayers, but I expect poor animation performance. – Geri Borbás Oct 14 '13 at 09:10

0 Answers0