14

I want to use blurring in my iOS app when it switch. Like PayPal and some other financial app where need to hide information. But I can't find any information or hint about this feature.

For example PayPal realization: http://40.media.tumblr.com/0334b065e28dfe2e325d32822d87246b/tumblr_mwcl35TZIt1qea4hso1_1280.jpg

Wain
  • 118,658
  • 15
  • 128
  • 151
Sul Tan
  • 143
  • 1
  • 5
  • 1
    You mean when you app goes to the background (is no longer active)? Did you search for duplicates? – Wain Aug 13 '15 at 07:52
  • Yes, application in background, but we can see screen this app on multitask panel. I need blur this screen to hide private information. – Sul Tan Aug 13 '15 at 08:05

1 Answers1

33

You need to add the following code to your applicationWillResignActive function

    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = window!.frame
    blurEffectView.tag = 221122

    self.window?.addSubview(blurEffectView)

Then in your applicationDidBecomeActive, use the line

self.window?.viewWithTag(221122)?.removeFromSuperview()
Shamas S
  • 7,507
  • 10
  • 46
  • 58
  • Thanks, it work! But after app all time have blur, even foreground. How I can abort blur after application become active? (I know it can be simple, but doesnt work. I use obj-c) – Sul Tan Aug 13 '15 at 08:33
  • @SulTan updated code. it's objC would be `[[self.window viewWithTag:221122] removeFromSuperview]` – Shamas S Aug 13 '15 at 08:53
  • 4
    All done, thanks! A small addition: `[[self.window viewWithTag:221122] removeFromSuperview]` need put in `applicationDidBecomeActive` too – Sul Tan Aug 13 '15 at 09:19
  • 2
    Notice that applicationWillEnterForeground is not called when the control center or notification center is shown then dismissed (and a couple of other events). Might consider moving the removeFromSuperView in applicationDidBecomeActive – valR Aug 30 '16 at 07:37