I want my self.view content should be visible but blurred, propose best way

117 Views Asked by At

In storyBoard, I added separate UIView as First responder in view controller.Then I added that view as subview of self.view. But I want self.view should be blurred when subview is shown. How can i do this?

I tried by applying

let imageView = UIImageView(image: UIImage(named: "blur2.jpg"))
imageView.frame = self.view.bounds
imageView.contentMode = .scaleAspectFit
self.view.addSubview(imageView)
let blurEffect = UIBlurEffect(style: .regular)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.frame = imageView.bounds
self.view.addSubview(blurredEffectView)


self.view.addSubview(view_Message)
view_Message.center = self.view.center
view_Message.alpha = 1
view_Message.layer.cornerRadius = 0.3
view_Message.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)

view_Message is UIView which is taken as FirstResponder in storyBoard.

But my self.view content goes invisible. I want My self.view should get blur(but should be shown lightly) at the same time I want my subview is shown.

4

There are 4 best solutions below

1
On BEST ANSWER

i suggest you to

  • 1. Take a UIView(let say myView) of frame self.view.bounds with clear as backgroundcolor
  • 2. Add imageView into it of same frame
  • 3. set backgroundcolor for imageView white,alpha nearly 0.7,and blur effect.
  • 4. Now add your view_Message into myView as SubView.
  • 5. Atlast add myView to self.view

or you can go by using UIVisualEffectBlur class either in storyboard or programmatically available for iOS 8+.

0
On

You can do like this

        let frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height )
        blurview = UIView.init(frame: frame)
        blurview.backgroundColor = UIColor.blackColor()
        blurview.layer.opacity = 0.5
        self.view.addSubview(blurview)
0
On

You can also use visualEffectView rather than blurEffect like this:

 let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
 visualEffectView.frame = view.bounds
 visualEffectView.alpha = 0.7
 self.view.addSubview(visualEffectView)
4
On

Check 3D view. It seems That your ImageView is On Top Of all views. This will hide all your views behind it.

Try

self.view.sendSubviewToBack(imageView)

at the end, This will send imagview at back an your all subviews will be visible.