Search code examples
iosswift3xcode8subviewuiblureffect

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


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.


Solution

  • 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+.