I have a UIView
with a blurEffect
defined as follows :
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)
This works fine and produces the following result (the blurred view is on top) :
What I want to achieve is to make the transition between the picture and the view more smooth, so that there is no clear line which divides the two, I am thinking of making the blurred view have a alpha
gradient which starts at 1.0
on top and goes to 0.0
at the bottom of the blurred view (same idea as a color gradient). This would make the transition much more gradual and smooth, however I am not sure how to achieve this kind of alpha gradient.
I added the following code :
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;
as suggested by the duplicate question, all this did was made the whole blurView disappear.