修复UIVisualEffectView额外的光线模糊,在白色背景上为灰色 [英] Fix UIVisualEffectView extra light blur being gray on white background
问题描述
Apple提供了此实时模糊视图类 UIVisualEffectView
,然后将其与 UIBlurEffect
,它采用三个可用的
Apple provides this live blurring view class UIVisualEffectView
and you use it with a UIBlurEffect
which takes one of three available UIBlurEffectStyle
s:
enum UIBlurEffectStyle : Int {
case ExtraLight
case Light
case Dark
}
现在出于演示目的,我用样式Light
和ExtraLight
设置了两个效果视图:
Now for demo purposes I set up two effect views with the styles Light
and ExtraLight
:
let lightBlur = UIBlurEffect(style: UIBlurEffectStyle.Light)
let extraLightBlur = UIBlurEffect(style: UIBlurEffectStyle.ExtraLight)
let lightView = UIVisualEffectView(effect: lightBlur)
lightView.frame = CGRectMake(10, 30, 150, 150)
self.view.addSubview(lightView)
let extraLightView = UIVisualEffectView(effect: extraLightBlur)
extraLightView.frame = CGRectMake(160, 30, 150, 150)
self.view.addSubview(extraLightView)
到目前为止,一切正常,一切正常,它们使图像模糊:
So far so good, everything works as expected, they blur images:
以及有关颜色的工作:
但是在白色背景下会发生这种情况:
but when it comes to a white background this happens:
左侧的Light
效果可以正常使用,但是右侧的ExtraLight
效果后面留有某种灰色正方形.
The Light
effect on the left works as expected, but the ExtraLight
effect on the right leaves some kind of gray square behind.
现在的问题是:有什么技巧或方法可以使我在白色背景上使用额外的光模糊效果(支持实时模糊)并消除那丑陋的灰色阴影?
Now the question: Is there any kind of trick or method that would enable me to use an extra light blur effect on white background (with live blurring support) AND remove that ugly gray shadow?
推荐答案
如果只希望模糊并且模糊的视图保持静止,则可以使用UIImageEffects
类并将tintColor
更改为完整" "白色:
If you just want the blur and your blurred view is gonna be stationary, you could use the UIImageEffects
class and change the tintColor
to a "full" white:
- (UIImage *)applyExtraLightEffect
{
UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82];
return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
}
据我所知,您无法在UIVisualEffectView
中进行更改.
As far as I know you can't change it in the UIVisualEffectView
.
这篇关于修复UIVisualEffectView额外的光线模糊,在白色背景上为灰色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!