Blur CALayer's Superlayer

2019-05-23 03:14发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-05-23 04:00

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];
查看更多
登录 后发表回答