Blur CALayer's Superlayer

[亡魂溺海] 提交于 2019-12-07 23:56:16

问题


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:


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


来源:https://stackoverflow.com/questions/2821551/blur-calayers-superlayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!