CALayer的backgroundFilters在UIView上不执行任何操作 [英] CALayer's backgroundFilters doesn nothing on UIView

查看:169
本文介绍了CALayer的backgroundFilters在UIView上不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将CIFilter添加到 CALayer 的backgroundFilters属性中,以使其在 UIView 中绘制。因此,我将 CALayer 子类化,并在初始化中执行以下操作:

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

然后我创建了 UIView 的子类,通过返回 + [UIView layerClass]

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

中的layers类,使它具有该自定义图层的图层上面的代码已执行!

This is working, the above code is executed!

但是,如果将此视图放在 UIImageView 上方,我希望图像是画模糊了我把这个观点。但事实并非如此!该视图的行为就像常规视图,并采用我设置为其 backgroundColor 属性的任何颜色/ Alpha值,但我只看到底层的 UIImageView

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!

推荐答案

CALayer的backgroundFilters在UIView上什么都不做的原因是不幸的是iOS中的图层不支持 backgroundFilters 属性。它位于在文档结尾,位于说明的结尾:

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:


特殊注意事项


iOS的图层不支持此属性。

This property is not supported on layers in iOS.

我自己被这个东西咬住了,试图插入 UIView 来模糊其后的内容。要模糊iOS上的视图,似乎需要做更多的工作(将UIViews内容复制到图像内,然后模糊并显示图像)。

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).

这篇关于CALayer的backgroundFilters在UIView上不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆