1

我有UIView一个blurEffect定义如下:

 var blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)

        let blurEffectView = UIVisualEffectView(effect: blurEffect)
        blurEffectView.frame = containerBar.bounds
        blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        self.containerBar.insertSubview(blurEffectView, atIndex: 1) //if you have more UIViews, use an insertSubview API to place it where needed
        self.containerBar.sendSubviewToBack(blurEffectView)

这工作正常并产生以下结果(模糊视图在顶部):

在此处输入图像描述

我想要实现的是使图片和视图之间的过渡更加平滑,这样就没有将两者分开的清晰线,我正在考虑使模糊视图具有alpha从顶部开始的渐变1.00.0在模糊视图的底部(与颜色渐变相同的想法)。这将使过渡更加渐进和平滑,但是我不确定如何实现这种 alpha 渐变。

我添加了以下代码:

            let gradientLayer = CAGradientLayer()
        gradientLayer.frame = containerBar.bounds;
        gradientLayer.colors =  [UIColor.whiteColor().CGColor, UIColor.clearColor().CGColor]
        gradientLayer.startPoint = CGPointMake(0.8, 1.0)
        gradientLayer.endPoint = CGPointMake(1.0, 1.0)
        blurEffectView.layer.mask = gradientLayer;

正如重复问题所建议的那样,所做的一切都是使整个 blurView 消失。

4

0 回答 0