2

I've got a CALayer and a sublayer in it. What i want to achieve is a blur of the superlayer (the area under the sublayer), just like the standard sheets do it. I've tried to set a .compositingFilter on the sublayer but this doesn't seem to work.

Any ideas how to solve this?

Code from the sublayers init:

CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
[blur setDefaults];     
self.layer.backgroundFilters = [NSArray arrayWithObject:blur];

1 Answers1

4

The above should work fine, depending on the context it is used in. E.g. with a simple super-layer containing an image, the following works for me:

CALayer *blurLayer = [CALayer layer];
CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
[blur setDefaults];     
blurLayer.backgroundFilters = [NSArray arrayWithObject:blur];    
[superLayer addSublayer:blurLayer];
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • I had the code above in the views **-(id)init**. When i did the same after adding it as a subview/layer it applied the effect as it should, otherwise not. –  May 12 '10 at 20:25
  • eaigner: Views don't ordinarily initialize in the `init` method. The correct initializer for NSView is `initWithFrame:`. The only reason to put it in `init` is if (1) the views determine their own size in that method, and call `[super initWithFrame:]` with the frame so constructed, and (2) you create the views explicitly using `alloc` and `init`. – Peter Hosey May 14 '10 at 08:48
  • Yes i know that. Only wanted to clarify where i put the code and used the short version. But of course initWithFrame would be the correct one. –  May 17 '10 at 17:14
  • To do what the OP wants, I assume you'd also need to capture a snapshot image of what's behind the current view and feed that to the CIGaussianBlur's `inputImage` parameter? – Slipp D. Thompson Oct 03 '13 at 01:37
  • Add `layerUsesCoreImageFilters = true` if you get the `CI filters are not supported by this layer tree` error, http://stackoverflow.com/questions/19540070/adding-cifilter-to-calayer-under-mavericks – Daniel Farrell Apr 17 '15 at 15:32