ios8 blur effect disappear - ios

Thanks for reading my question
I had some trouble stabilizing the intensity of blur effect
I had a UIImageView with blur effect (Extralight) which covered the whole view as a background
The intensity of the blur effect looked just fine
But after I added items onto the storyboard
the blur effect dimmed so much almost disappear
sorry i don't have enough reputation to upload pictures
anyone know what caused it, and how to solve?
Thank you very much!
override func viewDidLayoutSubviews() {
// set bg image and blur
bg.image = UIImage(named: "my portrait")
var blurEffect = UIBlurEffect(style: UIBlurEffectStyle.ExtraLight)
var blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = bg.bounds
bg.addSubview(blurView)
}

I think I found the reason
It is because the blur view is added under function ViewDidLayoutSubview
So the blur is added multiple times
That's the reason it's looks dimmer and dimmer

Related

blur effect of UIVisualEffect is not working

I have an ImageView that I want to apply blurEffect on it. I tried doing it from storyboard and programmatically but it's still not working . it's keep showing gray solid background.
I saw many videos on Youtube and many tutorials on the internet but still the same!
this is the code that I'm using right now.
view.addSubview(imageView)
let blur = UIBlurEffect(style: UIBlurEffect.Style.light)
let blureView = UIVisualEffectView(effect: blur)
blureView.frame = view.bounds
view.addSubview(blureView)
and here what I'm getting

iOS 10 - Blurred Background doesn't work anymore

Does anyone has problems with the UIBlurEffect on iOS10 ?
For some Reason the background of my button etc just gets a bit transparent and doesn't blurr anymore....
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.ExtraLight)
blurBackgroundView = UIVisualEffectView(effect: blurEffect)
blurBackgroundView.frame = frame
button = UIButton(frame: frame)
blurBackgroundView.layer.masksToBounds = true
backgroundColor = UIColor.clearColor()
addSubview(blurBackgroundView)
addSubview(button)
that's how the code looks....
If I change UIBlurEffectStyle.ExtraLight to UIBlurEffectStyle.Prominent based on the new documentation the Button is just clear... so no color at all!
Add whatever you want not to be blurred to your blurBackgroundView. So instead of:
addSubview(blurBackgroundView)
addSubview(button)
You'll have to:
blurBackgroundView.addSubview(button)
addSubview(blurBackgroundView)
Now every item in the current view, below your blurBackgroundView will get blurred, while your button will stay as it is.

Add UIView over blurred UIView

I am trying to create a popup menu over a blurred background. I created the function below to blur the view which works great, but when I try to add the menu, it gets blurred as well. I suppose I could take a snapshot of my view and put that under my popup, but I'm guessing there's a better way...
func blurView() {
let blurEffect = UIBlurEffect(style: .Light)
let effectView = UIVisualEffectView(effect: blurEffect)
effectView.frame = view.frame
view.addSubview(effectView)
effectView.alpha = 0
UIView.animateWithDuration(2.0) { effectView.alpha = 0.8 }
}
If you are just unhiding a previously added menu view to show the menu, then the blurView (which was just added) is probably in front of your menu view as well as everything else. After you add the blurView, when you want to show the menu, try something like:
menuView.hidden = false
view.bringSubviewToFront(menuView)
That should move the menu in front of the effect view so it doesn't get blurred.

Blur effect does not fill the entire View

I have a View controller that features a full screen UIImageView. When the controller loads, I just set a blur effect over the whole screen. The content mode for the UIImageView is set to scaleAspectFill. I set the blur effect like this:
#IBOutlet weak var previewImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
previewImage.image = userPhoto
let blur = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
blur.frame = self.view.bounds
previewImage.addSubview(blur)
}
when I test the app on an iPhone 6 I get this result:
There's an offset on the right an I can't figure out why. The picture underneath if is properly full screened but I can get the blur effect to fit over it...
****EDITED****
I applied the blur effect to the VC's view directly and now it works just fine, but I'd like to know why it doesn't work when I add the subview to the UIImage View...
I see two possible problems here:
Views are not laid out on the viewDidLoad stage. In this case you can force them to layout manualy:
override func viewDidLoad() {
super.viewDidLoad()
self.view.layoutIfNeeded()
...
}
You add subview to the previewImage, not to the root view. You must check your storyboard, or fix code:
override func viewDidLoad() {
super.viewDidLoad()
previewImage.image = userPhoto
let blur = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
blur.frame = self.view.bounds
self.view.insertSubview(blur, aboveSubview: previewImage)
}
Based on #kelin answer. You can even add the blur effect above your image in the interface builder.Just search for Visual Effect View with Blur in the objects section in the interface builder. Then add the Visual Effect View view above your image. It is also fully customizable through Attributes inspector. That way you you make sure that the blur will occupy the entire screen. It is also cleaner from architecture perspective , you do not need to configure your view through code.

TableView with image background and blur effect - swift

I have a little problem: I'd like to set an image to background in a TableViewController. I tried this:
class SquadreController: UITableViewController {
override func viewDidLoad()
{
super.viewDidLoad()
var sfondo = UIImage(named: "sfondo")
self.view.backgroundColor = UIColor(patternImage: sfondo!)
}
Then I give the blur effect to the view, like this:
let blur = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
view.addSubview(blurView)
But there is a big problem. I'm working in a TableView and the TableView, TableCell, NavigationItem, etc. have all disappeared after I apply the blur. Can someone help me?
Thanks a lot!
Try using view.insertSubView(blurView, atIndex: 0) instead of view.addSubview(blurView) as! UIImageView
This question is an older question and Epic Defeater's response does in a way work, there is a much better way to accomplish this. Instead of adding blurView, you need to override the background view. Specifically you need to override tableView.backgroundView.
let blur = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
tableView.backgroundView = blurView
This will only work if you have set the background color to clear.
We can also add a subview below or above any other views using insertSubview
//Inserting below your subView
self.view.insertSubview(subview1_name, belowSubview: subview2_name)
//Inserting above your subView
self.view.insertSubview(subview1_name, aboveSubview: subview2_name)
/// You can use any of your view, instead of self.view

Resources