Search code examples
cocoacore-animation

Blur CALayer's Superlayer


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];

Solution

  • 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];