0

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.

Narayana M
  • 15
  • 2
  • 10

4 Answers4

0

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)
Pragnesh Vitthani
  • 2,532
  • 20
  • 28
0

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

Jagdeep
  • 1,158
  • 11
  • 16
  • this article will solve your things https://www.raywenderlich.com/84043/ios-8-visual-effects-tutorial – Jagdeep Dec 20 '16 at 12:15
0

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)
Jitendra Modi
  • 2,344
  • 12
  • 34
-1

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.

Devang Tandel
  • 2,988
  • 1
  • 21
  • 43
  • That is working, but after dismissing the subview(view_Message), interaction is not working. No UIevents are firing(Even if i write isUserInteractionenabled = true – Narayana M Dec 20 '16 at 12:13
  • that is because you are sending View at back which sends it back in view stack disabling the interaction.. you can also try to bring it to front on dismissing the subview – Jagdeep Dec 20 '16 at 12:27
  • is there is anything mentioned about userInterraction in question? – Devang Tandel Dec 20 '16 at 12:48
  • why user interaction of other view would disabled due to the blurredview? WIll you explain me that? I am using this same since 2 years. There must be else causing the issue. – Devang Tandel Dec 20 '16 at 12:50