Reputation: 2026
I have an NSView. It has a layer. Inside of the layer, there are several sublayers. One of those sublayers needs to blend with the layers beneath it. I've set the top layer's compositingFilter
property, but no blending happens. :-(
Here's a visual representation:
Root Layer <-- myView.layer
|- Bottom Layer <-- myView.layer.sublayers[0]
|- Middle Layer <-- myView.layer.sublayers[1]
|- Top Layer <-- myView.layer.sublayers[2]
Root Layer
|- Bottom Layer
|- Middle Layer
|- Top Layer <-- Added filter to this layer.
I set the property like so:
self.topLayer.compositingFilter = [CIFilter filterWithName:@"CIMultiplyBlendMode"];
I assumed that the input image and background image would be supplied automatically with the contents
of each of the layers, but maybe I'm wrong. Am I?
TL;DR: How does a n00b composite a stack of layers together using blending modes?
P.S. I'm drawing the contents
of each layer using the delegate method, -drawLayer:inContext:
.
Upvotes: 3
Views: 1654
Reputation: 245
There is a flag you have to enable on NSView for it use filters on the layer:
[self.view setWantsLayer:YES];
[self.view setLayerUsesCoreImageFilters:YES];
I think this is specific to OS X and NSView and isn't necessary with UIView on iOS. Everything else looks correct to me.
Upvotes: 1