Skip to content

Instantly share code, notes, and snippets.

@chenr2
Last active August 29, 2015 14:25
Show Gist options
  • Save chenr2/e6a6794a6fe1a519fbe0 to your computer and use it in GitHub Desktop.
Save chenr2/e6a6794a6fe1a519fbe0 to your computer and use it in GitHub Desktop.

How do I get that frosted glass gaussian blur?

The Storyboard has views Visual Effect View with Blur and Visual Effect View with Blur and Vibrancy. You can almost treat this like empty views.

So if you wanted a login dialog box that came up as a modal, but blur the background:

  • The login dialog box would have its own View Controller
  • Open the login dialog box as a modal
  • Make sure the modal segue is Over Current Context so the screen below doesn't vanish
  • Add a Visual Effect View with Blur behind your other views, serving as a background
  • If you want, you can set the alpha on the Blur view to 0. Then animate the alpha on viewDidAppear
override func viewDidAppear(animated: Bool) {
    // add a semi-transparent background after the modal comes up
    UIView.animateWithDuration(0.5,
        delay: 0.0,
        options: .CurveEaseIn,
        animations: {
            self.visualEffectView.alpha = 1.0
        },
        completion: nil
    )
}

Sadly, if you do the animation above, you will get a warning:

<UIVisualEffectView 0x7ffd8e218790> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment