views:

241

answers:

1

Hi.

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  A: 

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
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.
Erik Aigner
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
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.
Erik Aigner