Search code examples
iosios6calayer

CALayer's backgroundFilters doesn nothing on UIView


I am trying to add a CIFilter to the backgroundFilters property of a CALayer to let this draw in a UIView. Therefore I subclassed CALayer and in the init execute the following:

CIFilter* blur = [CIFilter filterWithName:@"CIGaussianBlur"];
[blur setDefaults];
[blur setValue:@(10) forKey:@"inputRadius"];
self.backgroundFilters = @[ blur ];

Then I created a subclass of UIView that has this custom Layer as it's layer by returning the layers class in +[UIView layerClass]

This is working, the above code is executed!

However if I place this view above a UIImageView I would expect the image to be drawn blured where I put this view. But it doesn't! The view just behaves like a regular view and takes any color / alpha value I set to it's backgroundColor property, but I just see the underlaying UIImageView as it is, without a blur!


Solution

  • The reason for CALayer's backgroundFilters doing nothing on UIView is that unfortunately the backgroundFilters property is not supported on layers in iOS. It's inside inside the documentation, at the very end of the description:

    Special Considerations

    This property is not supported on layers in iOS.

    I got bitten by this myself trying to insert a UIView that blurs the contents behind it. To blur a view on iOS, some more work seems to be required (copying the UIViews content inside an image, then blurring and showing the image).