1

I have a view controller(PopOverViewController) being instantiated by another view controller(ListViewController).

Within ListViewController, PopOverViewController is modally presented:

popOverVC = self.storyboard?.instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController

popOverVC.modalPresentationStyle = .fullScreen

Within PopOverViewController, the PopOverViewController is animated in/out with CGAfflineTransformation:

    func showAnimate()
{
    self.shadowView.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
    self.view.alpha = 0.0;
    UIView.animate(withDuration: 0.3, animations: {
        self.view.alpha = 1.0
        self.shadowView.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
    });
}

func removeAnimate()
{
    UIView.animate(withDuration: 0.3, animations: {
        self.shadowView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
        self.view.alpha = 0.0;
    }, completion:{(finished: Bool) in
        if (finished)
        {
            self.view.removeFromSuperview()
        }
    });
}

In the viewDidLoad of the PopOverViewController, the background color is turned down:

self.view.backgroundColor = UIColor(white: 0, alpha: 0.7)

My Question: When the PopOver is presented, the background is still visible due to the alpha of the PopOver. I would like to blur this background when the PopOver is being presented, and have the blur disappear when the PopOver is closed.

I am stumped on how to do this.

Thank you!

Swift 3

Miles
  • 625
  • 2
  • 9
  • 18
  • 1
    Pretty sure this is what you are looking for: https://stackoverflow.com/a/25706250/4008175 – App Dev Guy Jun 08 '17 at 02:40
  • Possible duplicate of [Creating a blurring overlay view](https://stackoverflow.com/questions/17041669/creating-a-blurring-overlay-view) – App Dev Guy Jun 08 '17 at 02:41
  • 1
    @AppDevGuy Thank you for linking this. I will give it a try. – Miles Jun 08 '17 at 02:52
  • @AppDevGuy The blur works, however it covers the entire screen rather than the background (behind the Pop Over). – Miles Jun 08 '17 at 03:01
  • do `yourPopOverView.sendToBack( your blur view )` which will place it in background of the popup – App Dev Guy Jun 08 '17 at 03:02
  • @AppDevGuy Not working. It's still blurring the entire view. Would we be able to continue this in chat? Thank you very much for the help, I appreciate it. – Miles Jun 08 '17 at 03:10
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/146120/discussion-between-app-dev-guy-and-miles). – App Dev Guy Jun 08 '17 at 03:10
  • @AppDevGuy Hello, I ran into a small problem with the animation of the blur view. When the Pop Over fades in, the blur view "snaps" into full opacity, rather than fade in with the pop over. I've tried adjusting the alpha settings for the "showAnimate()", but it doesn't seem to be fixing this. I can send a video over that depicts it if you'd like? Thank you. – Miles Jun 08 '17 at 05:34
  • I have messaged in the chat. – App Dev Guy Jun 08 '17 at 05:50

1 Answers1

1
private func makeEffectView() {
        let effect: UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
        effectView = UIVisualEffectView(effect: effect)
        effectView.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.size.width, height:UIScreen.main.bounds.size.height)
        self.window?.addSubview(effectView)
    }



private func removeEffectView() {
        if effectView != nil {
            self.effectView.removeFromSuperview()
        }
    }
Sishu
  • 1,510
  • 1
  • 21
  • 48